jason-rails 0.7.3 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f1ff421bf5bed33c4d2cd6002c250100dd5b3af35ae8fa959afc0223a39c62d
4
- data.tar.gz: 999697ba053f7192a26cd12de431a2574c06438494968108b6903538b8bc871e
3
+ metadata.gz: b901c6b15b2b4f00d307c0e86811d660a68be05ac8c43f3d48c41412a020b4e8
4
+ data.tar.gz: 3fbed93cb66f5acffe86a8254f0be3ed67979bf93d72ab8faed77a0ae552fff3
5
5
  SHA512:
6
- metadata.gz: 5fcc8d66a00d598ee800cb873295a55200b5b0067cc0dc22277b5c850c7c336c730cb703156a753909a62b1c0af3287759054fbdc852cb8b8e3a171d356249b2
7
- data.tar.gz: 1e66522e216c727c03c92b2537fd8a666ea527e6b41cf3866c6c48fed7114e43b529d145077d4598e268066f40a551f605d2180948a9940a8a3e3cf222c0afbd
6
+ metadata.gz: 6959b8b6e2b97547a9c596d4efe5332339deb240c31c3951eb10e017e54932e529c851303e38bdc347c8ed89b4a209974fe790f3377128b0fb4229d14c490f66
7
+ data.tar.gz: a9a17d52153d5580efcd2940437b1f5eac249f7611d38a152a4a043ea35803f1de6d2ce9e53ecd0e8dee923efd47df1be3c1b1d73e515095a4356875e25f0438
data/CHANGELOG.md CHANGED
@@ -1,5 +1,5 @@
1
- ## v0.7.2
2
- - Add JasonContext to exports, for use in scenarios where you need to forward the context into some other React reconciler (e.g. `react-three-fiber`)
1
+ ## v0.7.3
2
+ - Added: Add JasonContext to exports, for use in scenarios where you need to forward the context into some other React reconciler (e.g. `react-three-fiber`)
3
3
  - Fixed: Unneeded `reload` in Publisher resulting in extra database calls
4
4
 
5
5
  ## v0.7.1
data/README.md CHANGED
@@ -52,6 +52,11 @@ Jason.setup do |config|
52
52
  end
53
53
  ```
54
54
 
55
+ Mount the Jason engine in `routes.rb`
56
+ ```ruby
57
+ mount Jason::Engine => "/jason"
58
+ ```
59
+
55
60
  ### In your frontend code
56
61
 
57
62
  First you need to wrap your root component in a `JasonProvider`.
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
- declare const JasonProvider: ({ reducers, middleware, enhancers, extraActions, children }: {
2
+ declare const JasonProvider: ({ reducers, middleware, enhancers, extraActions, transportOptions, children }: {
3
3
  reducers?: any;
4
4
  middleware?: any;
5
5
  enhancers?: any;
6
6
  extraActions?: any;
7
+ transportOptions?: any;
7
8
  children?: React.FC<{}> | undefined;
8
9
  }) => JSX.Element;
9
10
  export default JasonProvider;
@@ -7,8 +7,8 @@ const react_1 = __importDefault(require("react"));
7
7
  const useJason_1 = __importDefault(require("./useJason"));
8
8
  const react_redux_1 = require("react-redux");
9
9
  const JasonContext_1 = __importDefault(require("./JasonContext"));
10
- const JasonProvider = ({ reducers, middleware, enhancers, extraActions, children }) => {
11
- const [store, value] = useJason_1.default({ reducers, middleware, enhancers, extraActions });
10
+ const JasonProvider = ({ reducers, middleware, enhancers, extraActions, transportOptions = {}, children }) => {
11
+ const [store, value] = useJason_1.default({ reducers, middleware, enhancers, extraActions, transportOptions });
12
12
  if (!(store && value))
13
13
  return react_1.default.createElement("div", null); // Wait for async fetch of schema to complete
14
14
  return react_1.default.createElement(react_redux_1.Provider, { store: store },
@@ -1,4 +1,4 @@
1
- export default function createTransportAdapter(jasonConfig: any, handlePayload: any, dispatch: any, onConnect: any): {
1
+ export default function createTransportAdapter(jasonConfig: any, handlePayload: any, dispatch: any, onConnect: any, transportOptions: any): {
2
2
  getPayload: (config: any, options: any) => void;
3
3
  createSubscription: (config: any) => void;
4
4
  removeSubscription: (config: any) => void;
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const actionCableAdapter_1 = __importDefault(require("./transportAdapters/actionCableAdapter"));
7
7
  const pusherAdapter_1 = __importDefault(require("./transportAdapters/pusherAdapter"));
8
- function createTransportAdapter(jasonConfig, handlePayload, dispatch, onConnect) {
8
+ function createTransportAdapter(jasonConfig, handlePayload, dispatch, onConnect, transportOptions) {
9
9
  const { transportService } = jasonConfig;
10
10
  if (transportService === 'action_cable') {
11
- return actionCableAdapter_1.default(jasonConfig, handlePayload, dispatch, onConnect);
11
+ return actionCableAdapter_1.default(jasonConfig, handlePayload, dispatch, onConnect, transportOptions);
12
12
  }
13
13
  else if (transportService === 'pusher') {
14
14
  return pusherAdapter_1.default(jasonConfig, handlePayload, dispatch);
@@ -7,11 +7,12 @@ export declare const JasonContext: import("react").Context<{
7
7
  subscribe: null;
8
8
  eager: (entity: any, id: any, relations: any) => void;
9
9
  }>;
10
- export declare const JasonProvider: ({ reducers, middleware, enhancers, extraActions, children }: {
10
+ export declare const JasonProvider: ({ reducers, middleware, enhancers, extraActions, transportOptions, children }: {
11
11
  reducers?: any;
12
12
  middleware?: any;
13
13
  enhancers?: any;
14
14
  extraActions?: any;
15
+ transportOptions?: any;
15
16
  children?: import("react").FC<{}> | undefined;
16
17
  }) => JSX.Element;
17
18
  export declare const useAct: typeof _useAct;
@@ -1,4 +1,4 @@
1
- export default function actionCableAdapter(jasonConfig: any, handlePayload: any, dispatch: any, onConnected: any): {
1
+ export default function actionCableAdapter(jasonConfig: any, handlePayload: any, dispatch: any, onConnected: any, transportOptions: any): {
2
2
  getPayload: (config: any, options: any) => void;
3
3
  createSubscription: (config: any) => void;
4
4
  removeSubscription: (config: any) => void;
@@ -7,9 +7,10 @@ const actioncable_1 = require("@rails/actioncable");
7
7
  const restClient_1 = __importDefault(require("../restClient"));
8
8
  const uuid_1 = require("uuid");
9
9
  const lodash_1 = __importDefault(require("lodash"));
10
- function actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnected) {
10
+ function actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnected, transportOptions) {
11
11
  const consumerId = uuid_1.v4();
12
- const consumer = actioncable_1.createConsumer();
12
+ const { cableUrl } = transportOptions;
13
+ const consumer = cableUrl ? actioncable_1.createConsumer(cableUrl) : actioncable_1.createConsumer();
13
14
  const subscription = (consumer.subscriptions.create({
14
15
  channel: 'Jason::Channel'
15
16
  }, {
@@ -1,6 +1,7 @@
1
- export default function useJason({ reducers, middleware, enhancers, extraActions }: {
1
+ export default function useJason({ reducers, middleware, enhancers, transportOptions, extraActions }: {
2
2
  reducers?: any;
3
3
  middleware?: any[];
4
4
  enhancers?: any[];
5
5
  extraActions?: any;
6
+ transportOptions?: any;
6
7
  }): any[];
@@ -16,7 +16,7 @@ const humps_1 = require("humps");
16
16
  const blueimp_md5_1 = __importDefault(require("blueimp-md5"));
17
17
  const lodash_1 = __importDefault(require("lodash"));
18
18
  const react_1 = require("react");
19
- function useJason({ reducers, middleware = [], enhancers = [], extraActions }) {
19
+ function useJason({ reducers, middleware = [], enhancers = [], transportOptions = {}, extraActions }) {
20
20
  const [store, setStore] = react_1.useState(null);
21
21
  const [value, setValue] = react_1.useState(null);
22
22
  react_1.useEffect(() => {
@@ -37,7 +37,7 @@ function useJason({ reducers, middleware = [], enhancers = [], extraActions }) {
37
37
  let subOptions = {};
38
38
  function handlePayload(payload) {
39
39
  const { md5Hash } = payload;
40
- const { handlePayload } = payloadHandlers[md5Hash];
40
+ const { handlePayload } = payloadHandlers[md5Hash] || {};
41
41
  if (handlePayload) {
42
42
  handlePayload(payload);
43
43
  }
@@ -45,7 +45,7 @@ function useJason({ reducers, middleware = [], enhancers = [], extraActions }) {
45
45
  console.warn("Payload arrived with no handler", payload, payloadHandlers);
46
46
  }
47
47
  }
48
- const transportAdapter = createTransportAdapter_1.default(jasonConfig, handlePayload, dispatch, () => lodash_1.default.keys(configs).forEach(md5Hash => createSubscription(configs[md5Hash], subOptions[md5Hash])));
48
+ const transportAdapter = createTransportAdapter_1.default(jasonConfig, handlePayload, dispatch, () => lodash_1.default.keys(configs).forEach(md5Hash => createSubscription(configs[md5Hash], subOptions[md5Hash])), transportOptions);
49
49
  function createSubscription(config, options = {}) {
50
50
  // We need the hash to be consistent in Ruby / Javascript
51
51
  const hashableConfig = lodash_1.default(Object.assign({ conditions: {}, includes: {} }, config)).toPairs().sortBy(0).fromPairs().value();
data/client/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesr2323/jason",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "module": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
@@ -3,8 +3,8 @@ import useJason from './useJason'
3
3
  import { Provider } from 'react-redux'
4
4
  import JasonContext from './JasonContext'
5
5
 
6
- const JasonProvider = ({ reducers, middleware, enhancers, extraActions, children }: { reducers?: any, middleware?: any, enhancers?: any, extraActions?: any, children?: React.FC }) => {
7
- const [store, value] = useJason({ reducers, middleware, enhancers, extraActions })
6
+ const JasonProvider = ({ reducers, middleware, enhancers, extraActions, transportOptions = {}, children }: { reducers?: any, middleware?: any, enhancers?: any, extraActions?: any, transportOptions?: any, children?: React.FC }) => {
7
+ const [store, value] = useJason({ reducers, middleware, enhancers, extraActions, transportOptions })
8
8
 
9
9
  if(!(store && value)) return <div /> // Wait for async fetch of schema to complete
10
10
 
@@ -1,10 +1,10 @@
1
1
  import actionCableAdapter from './transportAdapters/actionCableAdapter'
2
2
  import pusherAdapter from './transportAdapters/pusherAdapter'
3
3
 
4
- export default function createTransportAdapter(jasonConfig, handlePayload, dispatch, onConnect) {
4
+ export default function createTransportAdapter(jasonConfig, handlePayload, dispatch, onConnect, transportOptions) {
5
5
  const { transportService } = jasonConfig
6
6
  if (transportService === 'action_cable') {
7
- return actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnect)
7
+ return actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnect, transportOptions)
8
8
  } else if (transportService === 'pusher') {
9
9
  return pusherAdapter(jasonConfig, handlePayload, dispatch)
10
10
  } else {
@@ -3,10 +3,12 @@ import restClient from '../restClient'
3
3
  import { v4 as uuidv4 } from 'uuid'
4
4
  import _ from 'lodash'
5
5
 
6
- export default function actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnected) {
6
+ export default function actionCableAdapter(jasonConfig, handlePayload, dispatch, onConnected, transportOptions) {
7
7
  const consumerId = uuidv4()
8
8
 
9
- const consumer = createConsumer()
9
+ const { cableUrl } = transportOptions
10
+ const consumer = cableUrl ? createConsumer(cableUrl) : createConsumer()
11
+
10
12
  const subscription = (consumer.subscriptions.create({
11
13
  channel: 'Jason::Channel'
12
14
  }, {
@@ -14,7 +14,7 @@ import md5 from 'blueimp-md5'
14
14
  import _ from 'lodash'
15
15
  import React, { useState, useEffect } from 'react'
16
16
 
17
- export default function useJason({ reducers, middleware = [], enhancers = [], extraActions }: { reducers?: any, middleware?: any[], enhancers?: any[], extraActions?: any }) {
17
+ export default function useJason({ reducers, middleware = [], enhancers = [], transportOptions = {}, extraActions }: { reducers?: any, middleware?: any[], enhancers?: any[], extraActions?: any, transportOptions?: any }) {
18
18
  const [store, setStore] = useState(null as any)
19
19
  const [value, setValue] = useState(null as any)
20
20
 
@@ -48,7 +48,7 @@ export default function useJason({ reducers, middleware = [], enhancers = [], ex
48
48
  function handlePayload(payload) {
49
49
  const { md5Hash } = payload
50
50
 
51
- const { handlePayload } = payloadHandlers[md5Hash]
51
+ const { handlePayload } = payloadHandlers[md5Hash] || {}
52
52
  if (handlePayload) {
53
53
  handlePayload(payload)
54
54
  } else {
@@ -56,7 +56,13 @@ export default function useJason({ reducers, middleware = [], enhancers = [], ex
56
56
  }
57
57
  }
58
58
 
59
- const transportAdapter = createTransportAdapater(jasonConfig, handlePayload, dispatch, () => _.keys(configs).forEach(md5Hash => createSubscription(configs[md5Hash], subOptions[md5Hash])))
59
+ const transportAdapter = createTransportAdapater(
60
+ jasonConfig,
61
+ handlePayload,
62
+ dispatch,
63
+ () => _.keys(configs).forEach(md5Hash => createSubscription(configs[md5Hash], subOptions[md5Hash])),
64
+ transportOptions
65
+ )
60
66
 
61
67
  function createSubscription(config, options = {}) {
62
68
  // We need the hash to be consistent in Ruby / Javascript
data/lib/jason.rb CHANGED
@@ -51,7 +51,11 @@ module Jason
51
51
  puts "Old config was #{previous_schema[model]}"
52
52
  puts "New config is #{config}"
53
53
  puts "Rebuilding cache for #{model}"
54
- model.classify.constantize.cache_all
54
+
55
+ # This is necessary to ensure all Rails methods have been added to model before we attempt to cache.
56
+ Rails.configuration.after_initialize do
57
+ model.classify.constantize.cache_all
58
+ end
55
59
  puts "Done"
56
60
  end
57
61
  end
data/lib/jason/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jason
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.5"
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.7.3
4
+ version: 0.7.5
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-04-18 00:00:00.000000000 Z
11
+ date: 2021-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails