jason-rails 0.6.8 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +2 -12
  5. data/app/workers/jason/outbound_message_queue_worker.rb +1 -1
  6. data/client/lib/addRelations.d.ts +1 -0
  7. data/client/lib/addRelations.js +39 -0
  8. data/client/lib/createJasonReducers.js +4 -2
  9. data/client/lib/createOptDis.d.ts +1 -1
  10. data/client/lib/createOptDis.js +9 -8
  11. data/client/lib/createServerActionQueue.d.ts +3 -2
  12. data/client/lib/createServerActionQueue.js +32 -6
  13. data/client/lib/createServerActionQueue.test.js +61 -6
  14. data/client/lib/createThenable.d.ts +1 -0
  15. data/client/lib/createThenable.js +5 -0
  16. data/client/lib/transportAdapters/actionCableAdapter.js +24 -4
  17. data/client/lib/transportAdapters/pusherAdapter.js +1 -1
  18. data/client/lib/useDraft.d.ts +1 -0
  19. data/client/lib/useDraft.js +13 -0
  20. data/client/lib/useEager.d.ts +1 -1
  21. data/client/lib/useEager.js +10 -5
  22. data/client/lib/useJason.js +0 -3
  23. data/client/package.json +1 -1
  24. data/client/src/addRelations.ts +33 -0
  25. data/client/src/createJasonReducers.ts +4 -2
  26. data/client/src/createOptDis.ts +10 -8
  27. data/client/src/createServerActionQueue.test.ts +60 -6
  28. data/client/src/createServerActionQueue.ts +41 -6
  29. data/client/src/transportAdapters/actionCableAdapter.ts +24 -5
  30. data/client/src/transportAdapters/pusherAdapter.ts +1 -2
  31. data/client/src/useDraft.ts +17 -0
  32. data/client/src/useEager.ts +9 -6
  33. data/client/src/useJason.ts +0 -3
  34. data/lib/jason.rb +2 -0
  35. data/lib/jason/api_model.rb +0 -4
  36. data/lib/jason/channel.rb +0 -7
  37. data/lib/jason/conditions_matcher.rb +88 -0
  38. data/lib/jason/consistency_checker.rb +61 -0
  39. data/lib/jason/graph_helper.rb +4 -0
  40. data/lib/jason/publisher.rb +34 -5
  41. data/lib/jason/subscription.rb +49 -13
  42. data/lib/jason/version.rb +1 -1
  43. metadata +12 -3
  44. data/client/src/makeEager.ts +0 -46
@@ -1,46 +0,0 @@
1
- import pluralize from 'pluralize'
2
- import _ from 'lodash'
3
- import { useSelector } from 'react-redux'
4
-
5
- export default function (schema) {
6
- function addRelations(s, objects, objectType, relations) {
7
- // first find out relation name
8
- if (_.isArray(relations)) {
9
- relations.forEach(relation => {
10
- objects = addRelations(s, objects, objectType, relation)
11
- })
12
- } else if (typeof(relations) === 'object') {
13
- const relation = Object.keys(relations)[0]
14
- const subRelations = relations[relation]
15
-
16
- objects = addRelations(s, objects, objectType, relation)
17
- objects[relation] = addRelations(s, objects[relation], pluralize(relation), subRelations)
18
- // #
19
- } else if (typeof(relations) === 'string') {
20
- const relation = relations
21
- if (_.isArray(objects)) {
22
- objects = objects.map(obj => addRelations(s, obj, objectType, relation))
23
- } else {
24
- const relatedObjects = _.values(s[pluralize(relation)].entities)
25
-
26
- if(pluralize.isSingular(relation)) {
27
- objects = { ...objects, [relation]: _.find(relatedObjects, { id: objects[relation + 'Id'] }) }
28
- } else {
29
- objects = { ...objects, [relation]: relatedObjects.filter(e => e[pluralize.singular(objectType) + 'Id'] === objects.id) }
30
- }
31
- }
32
- }
33
-
34
- return objects
35
- }
36
-
37
- function useEager(entity, id = null, relations = []) {
38
- if (id) {
39
- return useSelector(s => addRelations(s, { ...s[entity].entities[String(id)] }, entity, relations), _.isEqual)
40
- } else {
41
- return useSelector(s => addRelations(s, _.values(s[entity].entities), entity, relations), _.isEqual)
42
- }
43
- }
44
-
45
- return useEager
46
- }