jason-rails 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dae8eb61f7d3966c7e34ed81120a16e5c58f84d50ff6ea16ec87340d52cbf0ec
4
- data.tar.gz: cd4bc1d677ec413e2368c235632410e744ab3d47f94e7c65160b7665d3a6db45
3
+ metadata.gz: e62faa4e4f1246fa42810c324eec1f8fe96b8026ccdbe12f5b8bd7bc2df3bd4a
4
+ data.tar.gz: e4f829ce397c7192c173ba6e712a4b5873bd065d687cebf5ad72025f0436f51a
5
5
  SHA512:
6
- metadata.gz: 88130bf9bd8d557478de06bcdcb8901799425e3eeaf10a47a969152c13334659c8ffe36911fa2f3c18903a81c4291118e5f0c6daa72ac7a20545c095ab19f918
7
- data.tar.gz: 3e708e8b214b74cce9dc87ec07b04bf5a4d1453c7398050be657dfe0c34f7668708352d7bef7d9305ffbb1321728267cbab9ab61f03460af3f7987f7d0381253
6
+ metadata.gz: 6e3abfbfd6e0fbbe6c40dc7c0540448091cd440aaeec3580951a6148d6f1f92e61d5808b39ca02e8c564e1aa57beaf1de4d4cddb34e27b96ace09ca61d856d9a
7
+ data.tar.gz: b58a34f35981aea9b991f036cb83f9e059fa17a5932d9e9df78b6e86b5532484fe0dc115531365d5044d2f7df42355b5481a353233dcbd6744077b8fcbd58f18
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Jason
2
2
 
3
- Jason is still in a highly experimental phase with a rapidly changing API. Production use not recommended - but please give it a try!
3
+ Jason is still in an experimental phase with a rapidly changing API. It is being used in some production applications, however it is still in 0.x.x series versions, which means that any 0.x version bump could introduce breaking changes.
4
4
 
5
5
  ## The goal
6
6
 
@@ -14,6 +14,8 @@ I also wanted to avoid writing essentially the same code multiple times in diffe
14
14
 
15
15
  Jason attempts to minimize this repitition by auto-generating API endpoints, redux stores and actions from a single schema definition. Further it adds listeners to ActiveRecord models allowing the redux store to be subscribed to updates from a model or set of models.
16
16
 
17
+ An alternative way of thinking about Jason is "what if we applied the Flux/Redux state update pattern to make the _database_ the store?".
18
+
17
19
  ## Installation
18
20
 
19
21
  Add the gem and the NPM package
@@ -81,7 +83,7 @@ function extraActions(dispatch, store, restClient, act) {
81
83
  - `middleware` - Passed directly to `configureStore` with additional Jason middleware
82
84
 
83
85
  ## Usage
84
- Jason provides two custom hooks to access functionality.
86
+ Jason provides three custom hooks to access functionality.
85
87
 
86
88
  ### useAct
87
89
  This returns an object which allows you to access actions which both update models on the server, and perform an optimistic update to the Redux store.
@@ -126,6 +128,28 @@ export default function PostsList() {
126
128
  }
127
129
  ```
128
130
 
131
+ ### useEager
132
+ Jason stores all the data in a normalized form - one redux slice per model. Often you might want to get nested data from several slices for use in components. The `useEager` hook provides an API for doing that. Under the hood it's just a wrapper around useSelector, which aims to mimic the behaviour of Rails eager loading.
133
+
134
+ Example
135
+ This will fetch the comment as well as the post and user linked to it.
136
+
137
+ ```jsx
138
+ import React from 'react'
139
+ import { useSelector } from 'react-redux'
140
+ import { useEager } from '@jamesr2323/jason'
141
+ import _ from 'lodash'
142
+
143
+ export default function Comment({ id }) {
144
+ const comment = useEager('comments', id, ['post', 'user'])
145
+
146
+ return <div>
147
+ <p>{ comment.body }</p>
148
+ <p>Made on post { comment.post.name } by { comment.user.name }</p>
149
+ </div>
150
+ }
151
+ ```
152
+
129
153
  ## Authorization
130
154
 
131
155
  By default all models can be subscribed to and updated without authentication or authorization. Probably you want to lock down access.
@@ -35,10 +35,10 @@ class Jason::ApiController < ::ApplicationController
35
35
  all_instance_ids.insert(priority.to_i, instance.id)
36
36
 
37
37
  all_instance_ids.each_with_index do |id, i|
38
- model.find(id).update!(priority: i, skip_publish_json: true)
38
+ model.find(id).update!(priority: i)
39
39
  end
40
40
 
41
- model.publish_all(model.find(all_instance_ids))
41
+ model.find(all_instance_ids).each(&:force_publish_json)
42
42
  elsif action == 'upsert' || action == 'add'
43
43
  payload = api_model.permit(params)
44
44
  return render json: model.find_or_create_by_id!(payload).as_json(api_model.as_json_config)
@@ -0,0 +1 @@
1
+ export default function useEager(entity: any, id?: null, relations?: never[]): void;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const JasonContext_1 = __importDefault(require("./JasonContext"));
7
+ const react_1 = require("react");
8
+ function useEager(entity, id = null, relations = []) {
9
+ const { eager } = react_1.useContext(JasonContext_1.default);
10
+ return eager(entity, id, relations);
11
+ }
12
+ exports.default = useEager;
data/client/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesr2323/jason",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "module": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
@@ -0,0 +1,9 @@
1
+ import JasonContext from './JasonContext'
2
+ import { useContext } from 'react'
3
+
4
+ export default function useEager(entity, id = null, relations = []) {
5
+ const { eager } = useContext(JasonContext)
6
+
7
+ return eager(entity, id, relations)
8
+ }
9
+
data/lib/jason/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jason
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jason-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Rees
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-16 00:00:00.000000000 Z
11
+ date: 2021-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -168,6 +168,8 @@ files:
168
168
  - client/lib/transportAdapters/pusherAdapter.js
169
169
  - client/lib/useAct.d.ts
170
170
  - client/lib/useAct.js
171
+ - client/lib/useEager.d.ts
172
+ - client/lib/useEager.js
171
173
  - client/lib/useJason.d.ts
172
174
  - client/lib/useJason.js
173
175
  - client/lib/useJason.test.d.ts
@@ -194,6 +196,7 @@ files:
194
196
  - client/src/transportAdapters/actionCableAdapter.ts
195
197
  - client/src/transportAdapters/pusherAdapter.ts
196
198
  - client/src/useAct.ts
199
+ - client/src/useEager.ts
197
200
  - client/src/useJason.test.ts
198
201
  - client/src/useJason.ts
199
202
  - client/src/useSub.ts