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 +4 -4
- data/README.md +26 -2
- data/app/controllers/jason/api_controller.rb +2 -2
- data/client/lib/useEager.d.ts +1 -0
- data/client/lib/useEager.js +12 -0
- data/client/package.json +1 -1
- data/client/src/useEager.ts +9 -0
- data/lib/jason/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e62faa4e4f1246fa42810c324eec1f8fe96b8026ccdbe12f5b8bd7bc2df3bd4a
|
4
|
+
data.tar.gz: e4f829ce397c7192c173ba6e712a4b5873bd065d687cebf5ad72025f0436f51a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
38
|
+
model.find(id).update!(priority: i)
|
39
39
|
end
|
40
40
|
|
41
|
-
model.
|
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
data/lib/jason/version.rb
CHANGED
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.
|
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-
|
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
|