isomorfeus-redux 4.2.0 → 22.9.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +176 -0
- data/lib/app_state.rb +25 -0
- data/lib/isomorfeus/browser_store_api.rb +0 -16
- data/lib/isomorfeus/redux/config.rb +97 -14
- data/lib/isomorfeus/redux/handler.rb +35 -0
- data/lib/isomorfeus/redux/version.rb +5 -0
- data/lib/isomorfeus/redux_imports.rb +14 -0
- data/lib/{redux/reducers.rb → isomorfeus/redux_reducers.rb} +15 -13
- data/lib/isomorfeus-redux.rb +18 -30
- data/lib/local_store.rb +27 -30
- data/lib/redux/store.rb +156 -120
- data/lib/session_store.rb +28 -30
- metadata +24 -247
- data/lib/app_store.rb +0 -42
- data/lib/isomorfeus/core_ext/hash/deep_merge.rb +0 -34
- data/lib/isomorfeus/core_ext/kernel.rb +0 -30
- data/lib/isomorfeus/execution_environment.rb +0 -67
- data/lib/isomorfeus/redux/imports.rb +0 -17
- data/lib/redux/version.rb +0 -3
- data/lib/redux.rb +0 -118
- data/node_modules/.package-lock.json +0 -31
- data/node_modules/@babel/runtime/LICENSE +0 -22
- data/node_modules/@babel/runtime/README.md +0 -19
- data/node_modules/@babel/runtime/helpers/AsyncGenerator.js +0 -99
- data/node_modules/@babel/runtime/helpers/AwaitValue.js +0 -6
- data/node_modules/@babel/runtime/helpers/applyDecoratedDescriptor.js +0 -31
- data/node_modules/@babel/runtime/helpers/arrayLikeToArray.js +0 -12
- data/node_modules/@babel/runtime/helpers/arrayWithHoles.js +0 -6
- data/node_modules/@babel/runtime/helpers/arrayWithoutHoles.js +0 -8
- data/node_modules/@babel/runtime/helpers/assertThisInitialized.js +0 -10
- data/node_modules/@babel/runtime/helpers/asyncGeneratorDelegate.js +0 -57
- data/node_modules/@babel/runtime/helpers/asyncIterator.js +0 -16
- data/node_modules/@babel/runtime/helpers/asyncToGenerator.js +0 -38
- data/node_modules/@babel/runtime/helpers/awaitAsyncGenerator.js +0 -8
- data/node_modules/@babel/runtime/helpers/checkPrivateRedeclaration.js +0 -8
- data/node_modules/@babel/runtime/helpers/classApplyDescriptorDestructureSet.js +0 -23
- data/node_modules/@babel/runtime/helpers/classApplyDescriptorGet.js +0 -10
- data/node_modules/@babel/runtime/helpers/classApplyDescriptorSet.js +0 -14
- data/node_modules/@babel/runtime/helpers/classCallCheck.js +0 -8
- data/node_modules/@babel/runtime/helpers/classCheckPrivateStaticAccess.js +0 -8
- data/node_modules/@babel/runtime/helpers/classCheckPrivateStaticFieldDescriptor.js +0 -8
- data/node_modules/@babel/runtime/helpers/classExtractFieldDescriptor.js +0 -10
- data/node_modules/@babel/runtime/helpers/classNameTDZError.js +0 -6
- data/node_modules/@babel/runtime/helpers/classPrivateFieldDestructureSet.js +0 -11
- data/node_modules/@babel/runtime/helpers/classPrivateFieldGet.js +0 -11
- data/node_modules/@babel/runtime/helpers/classPrivateFieldInitSpec.js +0 -9
- data/node_modules/@babel/runtime/helpers/classPrivateFieldLooseBase.js +0 -10
- data/node_modules/@babel/runtime/helpers/classPrivateFieldLooseKey.js +0 -8
- data/node_modules/@babel/runtime/helpers/classPrivateFieldSet.js +0 -12
- data/node_modules/@babel/runtime/helpers/classPrivateMethodGet.js +0 -10
- data/node_modules/@babel/runtime/helpers/classPrivateMethodInitSpec.js +0 -9
- data/node_modules/@babel/runtime/helpers/classPrivateMethodSet.js +0 -6
- data/node_modules/@babel/runtime/helpers/classStaticPrivateFieldDestructureSet.js +0 -14
- data/node_modules/@babel/runtime/helpers/classStaticPrivateFieldSpecGet.js +0 -14
- data/node_modules/@babel/runtime/helpers/classStaticPrivateFieldSpecSet.js +0 -15
- data/node_modules/@babel/runtime/helpers/classStaticPrivateMethodGet.js +0 -9
- data/node_modules/@babel/runtime/helpers/classStaticPrivateMethodSet.js +0 -6
- data/node_modules/@babel/runtime/helpers/construct.js +0 -26
- data/node_modules/@babel/runtime/helpers/createClass.js +0 -18
- data/node_modules/@babel/runtime/helpers/createForOfIteratorHelper.js +0 -61
- data/node_modules/@babel/runtime/helpers/createForOfIteratorHelperLoose.js +0 -25
- data/node_modules/@babel/runtime/helpers/createSuper.js +0 -25
- data/node_modules/@babel/runtime/helpers/decorate.js +0 -401
- data/node_modules/@babel/runtime/helpers/defaults.js +0 -17
- data/node_modules/@babel/runtime/helpers/defineEnumerableProperties.js +0 -25
- data/node_modules/@babel/runtime/helpers/defineProperty.js +0 -17
- data/node_modules/@babel/runtime/helpers/esm/AsyncGenerator.js +0 -95
- data/node_modules/@babel/runtime/helpers/esm/AwaitValue.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/applyDecoratedDescriptor.js +0 -28
- data/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js +0 -9
- data/node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js +0 -4
- data/node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/asyncGeneratorDelegate.js +0 -54
- data/node_modules/@babel/runtime/helpers/esm/asyncIterator.js +0 -13
- data/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js +0 -35
- data/node_modules/@babel/runtime/helpers/esm/awaitAsyncGenerator.js +0 -4
- data/node_modules/@babel/runtime/helpers/esm/checkPrivateRedeclaration.js +0 -5
- data/node_modules/@babel/runtime/helpers/esm/classApplyDescriptorDestructureSet.js +0 -20
- data/node_modules/@babel/runtime/helpers/esm/classApplyDescriptorGet.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/classApplyDescriptorSet.js +0 -11
- data/node_modules/@babel/runtime/helpers/esm/classCallCheck.js +0 -5
- data/node_modules/@babel/runtime/helpers/esm/classCheckPrivateStaticAccess.js +0 -5
- data/node_modules/@babel/runtime/helpers/esm/classCheckPrivateStaticFieldDescriptor.js +0 -5
- data/node_modules/@babel/runtime/helpers/esm/classExtractFieldDescriptor.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/classNameTDZError.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldDestructureSet.js +0 -6
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldGet.js +0 -6
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldInitSpec.js +0 -5
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldLooseBase.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldLooseKey.js +0 -4
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldSet.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/classPrivateMethodGet.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/classPrivateMethodInitSpec.js +0 -5
- data/node_modules/@babel/runtime/helpers/esm/classPrivateMethodSet.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/classStaticPrivateFieldDestructureSet.js +0 -8
- data/node_modules/@babel/runtime/helpers/esm/classStaticPrivateFieldSpecGet.js +0 -8
- data/node_modules/@babel/runtime/helpers/esm/classStaticPrivateFieldSpecSet.js +0 -9
- data/node_modules/@babel/runtime/helpers/esm/classStaticPrivateMethodGet.js +0 -5
- data/node_modules/@babel/runtime/helpers/esm/classStaticPrivateMethodSet.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/construct.js +0 -18
- data/node_modules/@babel/runtime/helpers/esm/createClass.js +0 -15
- data/node_modules/@babel/runtime/helpers/esm/createForOfIteratorHelper.js +0 -57
- data/node_modules/@babel/runtime/helpers/esm/createForOfIteratorHelperLoose.js +0 -21
- data/node_modules/@babel/runtime/helpers/esm/createSuper.js +0 -19
- data/node_modules/@babel/runtime/helpers/esm/decorate.js +0 -396
- data/node_modules/@babel/runtime/helpers/esm/defaults.js +0 -14
- data/node_modules/@babel/runtime/helpers/esm/defineEnumerableProperties.js +0 -22
- data/node_modules/@babel/runtime/helpers/esm/defineProperty.js +0 -14
- data/node_modules/@babel/runtime/helpers/esm/extends.js +0 -17
- data/node_modules/@babel/runtime/helpers/esm/get.js +0 -20
- data/node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js +0 -6
- data/node_modules/@babel/runtime/helpers/esm/inherits.js +0 -15
- data/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +0 -6
- data/node_modules/@babel/runtime/helpers/esm/initializerDefineProperty.js +0 -9
- data/node_modules/@babel/runtime/helpers/esm/initializerWarningHelper.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/instanceof.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/interopRequireDefault.js +0 -5
- data/node_modules/@babel/runtime/helpers/esm/interopRequireWildcard.js +0 -51
- data/node_modules/@babel/runtime/helpers/esm/isNativeFunction.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/isNativeReflectConstruct.js +0 -12
- data/node_modules/@babel/runtime/helpers/esm/iterableToArray.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js +0 -29
- data/node_modules/@babel/runtime/helpers/esm/iterableToArrayLimitLoose.js +0 -14
- data/node_modules/@babel/runtime/helpers/esm/jsx.js +0 -46
- data/node_modules/@babel/runtime/helpers/esm/maybeArrayLike.js +0 -9
- data/node_modules/@babel/runtime/helpers/esm/newArrowCheck.js +0 -5
- data/node_modules/@babel/runtime/helpers/esm/nonIterableRest.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/objectDestructuringEmpty.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/objectSpread.js +0 -19
- data/node_modules/@babel/runtime/helpers/esm/objectSpread2.js +0 -39
- data/node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js +0 -19
- data/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +0 -14
- data/node_modules/@babel/runtime/helpers/esm/package.json +0 -3
- data/node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js +0 -11
- data/node_modules/@babel/runtime/helpers/esm/readOnlyError.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/set.js +0 -51
- data/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js +0 -8
- data/node_modules/@babel/runtime/helpers/esm/skipFirstGeneratorNext.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/slicedToArray.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/slicedToArrayLoose.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/superPropBase.js +0 -9
- data/node_modules/@babel/runtime/helpers/esm/taggedTemplateLiteral.js +0 -11
- data/node_modules/@babel/runtime/helpers/esm/taggedTemplateLiteralLoose.js +0 -8
- data/node_modules/@babel/runtime/helpers/esm/tdz.js +0 -3
- data/node_modules/@babel/runtime/helpers/esm/temporalRef.js +0 -5
- data/node_modules/@babel/runtime/helpers/esm/temporalUndefined.js +0 -1
- data/node_modules/@babel/runtime/helpers/esm/toArray.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/toConsumableArray.js +0 -7
- data/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +0 -13
- data/node_modules/@babel/runtime/helpers/esm/toPropertyKey.js +0 -6
- data/node_modules/@babel/runtime/helpers/esm/typeof.js +0 -15
- data/node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js +0 -9
- data/node_modules/@babel/runtime/helpers/esm/wrapAsyncGenerator.js +0 -6
- data/node_modules/@babel/runtime/helpers/esm/wrapNativeSuper.js +0 -37
- data/node_modules/@babel/runtime/helpers/esm/wrapRegExp.js +0 -65
- data/node_modules/@babel/runtime/helpers/esm/writeOnlyError.js +0 -3
- data/node_modules/@babel/runtime/helpers/extends.js +0 -21
- data/node_modules/@babel/runtime/helpers/get.js +0 -27
- data/node_modules/@babel/runtime/helpers/getPrototypeOf.js +0 -10
- data/node_modules/@babel/runtime/helpers/inherits.js +0 -19
- data/node_modules/@babel/runtime/helpers/inheritsLoose.js +0 -10
- data/node_modules/@babel/runtime/helpers/initializerDefineProperty.js +0 -12
- data/node_modules/@babel/runtime/helpers/initializerWarningHelper.js +0 -6
- data/node_modules/@babel/runtime/helpers/instanceof.js +0 -10
- data/node_modules/@babel/runtime/helpers/interopRequireDefault.js +0 -8
- data/node_modules/@babel/runtime/helpers/interopRequireWildcard.js +0 -54
- data/node_modules/@babel/runtime/helpers/isNativeFunction.js +0 -6
- data/node_modules/@babel/runtime/helpers/isNativeReflectConstruct.js +0 -15
- data/node_modules/@babel/runtime/helpers/iterableToArray.js +0 -6
- data/node_modules/@babel/runtime/helpers/iterableToArrayLimit.js +0 -32
- data/node_modules/@babel/runtime/helpers/iterableToArrayLimitLoose.js +0 -17
- data/node_modules/@babel/runtime/helpers/jsx.js +0 -50
- data/node_modules/@babel/runtime/helpers/maybeArrayLike.js +0 -13
- data/node_modules/@babel/runtime/helpers/newArrowCheck.js +0 -8
- data/node_modules/@babel/runtime/helpers/nonIterableRest.js +0 -6
- data/node_modules/@babel/runtime/helpers/nonIterableSpread.js +0 -6
- data/node_modules/@babel/runtime/helpers/objectDestructuringEmpty.js +0 -6
- data/node_modules/@babel/runtime/helpers/objectSpread.js +0 -23
- data/node_modules/@babel/runtime/helpers/objectSpread2.js +0 -42
- data/node_modules/@babel/runtime/helpers/objectWithoutProperties.js +0 -23
- data/node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js +0 -17
- data/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js +0 -16
- data/node_modules/@babel/runtime/helpers/readOnlyError.js +0 -6
- data/node_modules/@babel/runtime/helpers/set.js +0 -55
- data/node_modules/@babel/runtime/helpers/setPrototypeOf.js +0 -12
- data/node_modules/@babel/runtime/helpers/skipFirstGeneratorNext.js +0 -10
- data/node_modules/@babel/runtime/helpers/slicedToArray.js +0 -14
- data/node_modules/@babel/runtime/helpers/slicedToArrayLoose.js +0 -14
- data/node_modules/@babel/runtime/helpers/superPropBase.js +0 -13
- data/node_modules/@babel/runtime/helpers/taggedTemplateLiteral.js +0 -14
- data/node_modules/@babel/runtime/helpers/taggedTemplateLiteralLoose.js +0 -11
- data/node_modules/@babel/runtime/helpers/tdz.js +0 -6
- data/node_modules/@babel/runtime/helpers/temporalRef.js +0 -10
- data/node_modules/@babel/runtime/helpers/temporalUndefined.js +0 -4
- data/node_modules/@babel/runtime/helpers/toArray.js +0 -14
- data/node_modules/@babel/runtime/helpers/toConsumableArray.js +0 -14
- data/node_modules/@babel/runtime/helpers/toPrimitive.js +0 -17
- data/node_modules/@babel/runtime/helpers/toPropertyKey.js +0 -11
- data/node_modules/@babel/runtime/helpers/typeof.js +0 -22
- data/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js +0 -13
- data/node_modules/@babel/runtime/helpers/wrapAsyncGenerator.js +0 -10
- data/node_modules/@babel/runtime/helpers/wrapNativeSuper.js +0 -45
- data/node_modules/@babel/runtime/helpers/wrapRegExp.js +0 -72
- data/node_modules/@babel/runtime/helpers/writeOnlyError.js +0 -6
- data/node_modules/@babel/runtime/package.json +0 -848
- data/node_modules/@babel/runtime/regenerator/index.js +0 -1
- data/node_modules/redux/LICENSE.md +0 -21
- data/node_modules/redux/README.md +0 -322
- data/node_modules/redux/dist/redux.js +0 -768
- data/node_modules/redux/dist/redux.min.js +0 -1
- data/node_modules/redux/es/redux.js +0 -716
- data/node_modules/redux/es/redux.mjs +0 -1
- data/node_modules/redux/index.d.ts +0 -776
- data/node_modules/redux/lib/redux.js +0 -730
- data/node_modules/redux/package.json +0 -108
- data/node_modules/redux/src/applyMiddleware.js +0 -41
- data/node_modules/redux/src/bindActionCreators.js +0 -52
- data/node_modules/redux/src/combineReducers.js +0 -175
- data/node_modules/redux/src/compose.js +0 -22
- data/node_modules/redux/src/createStore.js +0 -347
- data/node_modules/redux/src/index.js +0 -37
- data/node_modules/redux/src/utils/actionTypes.js +0 -17
- data/node_modules/redux/src/utils/formatProdErrorMessage.js +0 -15
- data/node_modules/redux/src/utils/isPlainObject.js +0 -14
- data/node_modules/redux/src/utils/kindOf.js +0 -70
- data/node_modules/redux/src/utils/symbol-observable.js +0 -3
- data/node_modules/redux/src/utils/warning.js +0 -19
- data/node_modules/regenerator-runtime/LICENSE +0 -21
- data/node_modules/regenerator-runtime/README.md +0 -31
- data/node_modules/regenerator-runtime/package.json +0 -19
- data/node_modules/regenerator-runtime/path.js +0 -11
- data/node_modules/regenerator-runtime/runtime.js +0 -754
- data/package.json +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb2a80f69bf9d2fd8072da217b8688c44371ee042cdd5606b0121993f9853fe0
|
4
|
+
data.tar.gz: 9eada94e693fcb7c773186d477826791ae9ec6dd8a8d005338e529ea4a795a48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e253576a134048de72a7dbf89c564d9d9c62be911c076fdf6a07c4386bbffff889a886aea99f2d9d98f8cfcfb4c88b434f9cf5f580132c8e627f3a82f624ecb
|
7
|
+
data.tar.gz: 97e17080904cf7491f04d8776b0257e1b6aa6969be6b23d24c003b275c308aecb9535f342c865bed41e827a2da06b10226c1909b5ab99f3cdb58b8967f23a6b8
|
data/README.md
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
<h1 align="center">
|
2
|
+
<img src="https://github.com/isomorfeus/isomorfeus-project/blob/master/isomorfeus-redux/Logo.png?raw=true" align="center" width="234" height="112"/><br/>
|
3
|
+
Isomorfeus Redux<br/>
|
4
|
+
</h1>
|
5
|
+
|
6
|
+
Redux implemented in Ruby (kinda) for the Isomorfeus Framework Project.
|
7
|
+
|
8
|
+
### Community and Support
|
9
|
+
At the [Isomorfeus Framework Project](https://isomorfeus.com)
|
10
|
+
|
11
|
+
## Versioning
|
12
|
+
As of version 22.8 isomorfeus-redux implements its own redux like behavior in ruby without depending on the javascript redux package anymore.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
Simply add it to the Gemfile:
|
16
|
+
```ruby
|
17
|
+
gem 'isomorfeus-redux'
|
18
|
+
```
|
19
|
+
then `bundle install`
|
20
|
+
and to your client code add:
|
21
|
+
```ruby
|
22
|
+
require 'isomorfeus-redux'
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage within Isomorfeus
|
26
|
+
|
27
|
+
Lucid Components have store access integrated, see the isomorfeus-preact documentation.
|
28
|
+
|
29
|
+
The following stores are available:
|
30
|
+
- AppState - reactive state managed by redux
|
31
|
+
- LocalStore - convenient access to the Browsers localStorage, changes from within ruby can be subscribed to
|
32
|
+
- SessionStore - convenient access to the Browsers sessionStorage, changes from within ruby can be subscribed to
|
33
|
+
|
34
|
+
### AppState
|
35
|
+
All keys must be Strings or Symbols! All values must be serializable, simple types preferred!
|
36
|
+
|
37
|
+
Example Usage:
|
38
|
+
```ruby
|
39
|
+
# setting a value:
|
40
|
+
AppState.set_state(some_key: 10)
|
41
|
+
|
42
|
+
# getting a value:
|
43
|
+
val = AppStore[:some_key]
|
44
|
+
val = AppStore.get(:some_key)
|
45
|
+
|
46
|
+
# or use dig
|
47
|
+
val = AppStore.dig(:some_key, :some_other_key)
|
48
|
+
|
49
|
+
# subscribing to changes
|
50
|
+
unsub = AppStore.subscribe do
|
51
|
+
@val = AppStore.some_key
|
52
|
+
end
|
53
|
+
|
54
|
+
# unsubscribe if notification of changes is no longer wanted
|
55
|
+
AppStore.unsubscribe(unsub)
|
56
|
+
```
|
57
|
+
|
58
|
+
### LocalStore
|
59
|
+
All keys and values must be Strings or Symbols!
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# setting a value:
|
63
|
+
LocalStore[:some_key] = 10
|
64
|
+
LocalStore.set(:some_key, 10)
|
65
|
+
|
66
|
+
# getting a value:
|
67
|
+
val = LocalStore[:some_key]
|
68
|
+
val = LocalStore.get(:some_key)
|
69
|
+
|
70
|
+
# deleting a value
|
71
|
+
LocalStore.delete(:some_key)
|
72
|
+
|
73
|
+
# clearing the store
|
74
|
+
LocalStore.clear
|
75
|
+
|
76
|
+
# subscribing to changes
|
77
|
+
unsub = LocalStore.subscribe do
|
78
|
+
@val = LocalStore.some_key
|
79
|
+
end
|
80
|
+
|
81
|
+
# unsubscribe if notification of changes is no longer wanted
|
82
|
+
LocalStore.unsubscribe(unsub)
|
83
|
+
```
|
84
|
+
|
85
|
+
### SessionStore
|
86
|
+
All keys and values must be Strings or Symbols!
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
# setting a value:
|
90
|
+
SessionStore[:some_key] = 10
|
91
|
+
SessionStore.set(:some_key, 10)
|
92
|
+
|
93
|
+
# getting a value:
|
94
|
+
val = SessionStore[:some_key]
|
95
|
+
val = SessionStore.get(:some_key)
|
96
|
+
|
97
|
+
# deleting a value
|
98
|
+
SessionStore.delete(:some_key)
|
99
|
+
|
100
|
+
# clearing the store
|
101
|
+
SessionStore.clear
|
102
|
+
|
103
|
+
# subscribing to changes
|
104
|
+
unsub = SessionStore.subscribe do
|
105
|
+
@val = SessionStore.some_key
|
106
|
+
end
|
107
|
+
|
108
|
+
# unsubscribe if notification of changes is no longer wanted
|
109
|
+
LocalStore.unsubscribe(unsub)
|
110
|
+
```
|
111
|
+
|
112
|
+
## Advanced Usage
|
113
|
+
|
114
|
+
### Creating a Store
|
115
|
+
A store can be created using:
|
116
|
+
```ruby
|
117
|
+
reducer_hash = { your_store_key_name: reducer }
|
118
|
+
preloaded_state = { your_store_key_name: { key: "Value" }}
|
119
|
+
store = Redux::Store.new(reducer_hash, preloaded_state, middleware)
|
120
|
+
```
|
121
|
+
- **reducer** is a ruby proc.
|
122
|
+
- **reducer_hash** Multiple keys with procs may be given in the Hash.
|
123
|
+
- **preloaded_state** optional, can be a Ruby Hash. If provided, Hash keys must be equal to the keys of the reducer hash
|
124
|
+
- **middleware** optional, a ruby proc or array of ruby procs.
|
125
|
+
|
126
|
+
### Creating a Reducer
|
127
|
+
A reducer is simply a ruby proc:
|
128
|
+
```ruby
|
129
|
+
reducer = proc do |prev_state, action|
|
130
|
+
# do something here
|
131
|
+
{}.merge(prev_state)
|
132
|
+
end
|
133
|
+
```
|
134
|
+
|
135
|
+
### Adding a reducer to the global store
|
136
|
+
```ruby
|
137
|
+
Redux::Store.add_reducers(your_store_key_name: reducer)
|
138
|
+
```
|
139
|
+
### Middleware
|
140
|
+
|
141
|
+
A middleware must be ruby proc with the following signature:
|
142
|
+
```ruby
|
143
|
+
middleware = proc do |action, next_middleware|
|
144
|
+
# do something useful and when finished and if desired, call the next middleware
|
145
|
+
next_middleware.call(action)
|
146
|
+
# not calling the next middleware will prevent the store update
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
### Global Store
|
151
|
+
The store is available from anywhere within Opal Ruby context as:
|
152
|
+
```ruby
|
153
|
+
Isomorfeus.store
|
154
|
+
```
|
155
|
+
|
156
|
+
### Other Rubyfications
|
157
|
+
- `dispatch` accepts a Ruby Hash
|
158
|
+
- `get_state` returns a Ruby Hash
|
159
|
+
- `subscribe` accepts a Ruby proc or block as listener:
|
160
|
+
```ruby
|
161
|
+
Isomorfeus.store.subscribe do
|
162
|
+
# something useful here
|
163
|
+
end
|
164
|
+
```
|
165
|
+
|
166
|
+
### Setup
|
167
|
+
If isomorfeus-redux is used in isolation, these methods can be used:
|
168
|
+
```ruby
|
169
|
+
Redux::Store.add_middleware(middleware) # middleware must be ruby proc
|
170
|
+
Redux::Store.init! # initializes the global store
|
171
|
+
```
|
172
|
+
|
173
|
+
### Specs and Benchmarks
|
174
|
+
- clone repo
|
175
|
+
- `bundle install`
|
176
|
+
- `rake`
|
data/lib/app_state.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
class AppState
|
2
|
+
class << self
|
3
|
+
def [](key)
|
4
|
+
Isomorfeus.store.get_state.dig(:application_state, key)
|
5
|
+
end
|
6
|
+
alias get []
|
7
|
+
|
8
|
+
def dig(key, *other_keys)
|
9
|
+
Isomorfeus.store.get_state.dig(:application_state, key, *other_keys)
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_state(update)
|
13
|
+
action = { type: 'APPLICATION_STATE', state: update }
|
14
|
+
Isomorfeus.store.deferred_dispatch(action)
|
15
|
+
end
|
16
|
+
|
17
|
+
def subscribe(&block)
|
18
|
+
Isomorfeus.store.subscribe(&block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def unsubscribe(unsubscriber)
|
22
|
+
Isomorfeus.store.unsubscribe(unsubscriber)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,21 +1,5 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module BrowserStoreApi
|
3
|
-
def promise_get(key)
|
4
|
-
Promise.new.resolve(get(key))
|
5
|
-
end
|
6
|
-
|
7
|
-
def promise_set(key, value)
|
8
|
-
Promise.new.resolve(set(key, value))
|
9
|
-
end
|
10
|
-
|
11
|
-
def promise_delete(key)
|
12
|
-
Promise.new.resolve(delete(key))
|
13
|
-
end
|
14
|
-
|
15
|
-
def promise_clear
|
16
|
-
Promise.new.resolve(clear)
|
17
|
-
end
|
18
|
-
|
19
3
|
def subscribe(&block)
|
20
4
|
key = SecureRandom.uuid
|
21
5
|
subscribers[key] = block
|
@@ -1,19 +1,102 @@
|
|
1
1
|
module Isomorfeus
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
if RUBY_ENGINE == 'opal'
|
3
|
+
class << self
|
4
|
+
attr_reader :store_initialized
|
5
|
+
attr_reader :store
|
6
|
+
|
7
|
+
def client_init_after_store_class_names
|
8
|
+
@client_init_after_store_class_names ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_client_init_after_store_class_name(init_class_name)
|
12
|
+
client_init_after_store_class_names << init_class_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute_init_classes
|
16
|
+
client_init_class_names.each do |constant|
|
17
|
+
constant.constantize.send(:init)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute_init_after_store_classes
|
22
|
+
client_init_after_store_class_names.each do |constant_name|
|
23
|
+
constant_name.constantize.send(:init)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def init_store
|
28
|
+
return if store_initialized
|
29
|
+
@store_initialized = true
|
30
|
+
force_init_store!
|
31
|
+
end
|
32
|
+
|
33
|
+
def force_init_store!
|
34
|
+
# at least one reducer must have been added at this stage
|
35
|
+
# this happened in isomorfeus-react.rb, where the component reducers were added
|
36
|
+
@store = ::Redux::Store.init!
|
37
|
+
`Opal.Isomorfeus.store = #@store`
|
38
|
+
end
|
39
|
+
|
40
|
+
def something_loading!
|
41
|
+
@something_loading = true
|
42
|
+
end
|
43
|
+
|
44
|
+
def something_loading?
|
45
|
+
res = @something_loading
|
46
|
+
@something_loading = false
|
47
|
+
res
|
48
|
+
end
|
49
|
+
|
50
|
+
def reset_something_loading
|
51
|
+
@something_loading = false
|
52
|
+
end
|
10
53
|
end
|
54
|
+
else # RUBY_ENGINE
|
55
|
+
class << self
|
56
|
+
attr_accessor :server_init_class_names
|
11
57
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
58
|
+
def execute_init_classes
|
59
|
+
server_init_class_names.each do |constant|
|
60
|
+
constant.constantize.send(:init)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def store_initialized
|
65
|
+
Thread.current[:@_isomorfeus_store_initialized]
|
66
|
+
end
|
67
|
+
|
68
|
+
def store
|
69
|
+
Thread.current[:@_isomorfeus_store]
|
70
|
+
end
|
71
|
+
|
72
|
+
def init_store
|
73
|
+
return if store_initialized
|
74
|
+
Thread.current[:@_isomorfeus_store_initialized] = true
|
75
|
+
force_init_store!
|
76
|
+
end
|
77
|
+
|
78
|
+
def force_init_store!
|
79
|
+
# at least one reducer must have been added at this stage
|
80
|
+
# this happened in isomorfeus-preact.rb, where the component reducers were added
|
81
|
+
Thread.current[:@_isomorfeus_store] = ::Redux::Store.init!
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def something_loading!
|
86
|
+
Thread.current[:isomorfeus_something_loading] = true
|
87
|
+
end
|
88
|
+
|
89
|
+
def something_loading?
|
90
|
+
res = Thread.current[:isomorfeus_something_loading]
|
91
|
+
Thread.current[:isomorfeus_something_loading] = false
|
92
|
+
res
|
93
|
+
end
|
94
|
+
|
95
|
+
def reset_something_loading
|
96
|
+
Thread.current[:isomorfeus_something_loading] = false
|
97
|
+
end
|
17
98
|
end
|
18
|
-
|
99
|
+
|
100
|
+
server_init_class_names = []
|
101
|
+
end # RUBY_ENGINE
|
19
102
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Isomorfeus
|
4
|
+
module Redux
|
5
|
+
class Handler < LucidHandler
|
6
|
+
# responsible for handling LucidObject and LucidQuery
|
7
|
+
|
8
|
+
def process_request(response_agent)
|
9
|
+
# promise_send_path('Isomorfeus::Redux::Handler', [actions...])
|
10
|
+
response_agent.outer_result = { state: {} } unless response_agent.outer_result
|
11
|
+
Isomorfeus.init_store
|
12
|
+
isto = Isomorfeus.store
|
13
|
+
response_agent.request.each do |action|
|
14
|
+
action.transform_keys!(&:to_sym)
|
15
|
+
isto.clear!
|
16
|
+
if current_user.respond_to?(:reload)
|
17
|
+
cu = current_user
|
18
|
+
Thread.current[:isomorfeus_user] = LocalSystem.new
|
19
|
+
begin
|
20
|
+
cu.reload
|
21
|
+
ensure
|
22
|
+
Thread.current[:isomorfeus_user] = cu
|
23
|
+
end
|
24
|
+
end
|
25
|
+
isto.dispatch(action)
|
26
|
+
response_agent.outer_result[:state].deep_merge!(isto.get_state)
|
27
|
+
end
|
28
|
+
response_agent.agent_result = { success: 'ok' }
|
29
|
+
rescue Exception => e
|
30
|
+
STDERR.puts "Isomorfeus::Redux::Handler exception #{e.message}\n#{e.backtrace&.join("\n")}" if Isomorfeus.development?
|
31
|
+
response_agent.error = { error: "Isomorfeus::Redux::Handler: #{e.message}\n#{e.backtrace&.join("\n") if !Isomorfeus.production?}" }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Isomorfeus
|
2
|
+
module ReduxImports
|
3
|
+
def self.add
|
4
|
+
# make sure static app stylesheets are imported first, if provided
|
5
|
+
imports_path = File.join(Isomorfeus.app_root, 'imports')
|
6
|
+
if Dir.exist?(imports_path)
|
7
|
+
%w[sass scss css].each do |ending|
|
8
|
+
styles_file = File.join(imports_path, 'stylesheets.' + ending)
|
9
|
+
Isomorfeus.add_web_js_import(styles_file) if File.exist?(styles_file)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,21 +1,22 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
def self.
|
1
|
+
module Isomorfeus
|
2
|
+
module ReduxReducers
|
3
|
+
def self.add_application_reducers
|
4
4
|
unless @_application_reducers_added
|
5
5
|
@_application_reducers_added = true
|
6
|
-
|
6
|
+
|
7
|
+
app_reducer = proc do |prev_state, action|
|
7
8
|
case action[:type]
|
8
9
|
when 'APPLICATION_STATE'
|
9
10
|
if action.key?(:set_state)
|
10
11
|
action[:set_state]
|
11
12
|
else
|
12
|
-
new_state =
|
13
|
+
new_state = prev_state.dup # make a copy of state
|
13
14
|
if action.key?(:collected)
|
14
15
|
action[:collected].each do |act|
|
15
|
-
new_state.merge!(act[:
|
16
|
+
new_state.merge!(act[:state])
|
16
17
|
end
|
17
18
|
else
|
18
|
-
new_state.merge!(action[:
|
19
|
+
new_state.merge!(action[:state])
|
19
20
|
end
|
20
21
|
new_state
|
21
22
|
end
|
@@ -24,21 +25,21 @@ module Redux
|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
class_reducer =
|
28
|
+
class_reducer = proc do |prev_state, action|
|
28
29
|
case action[:type]
|
29
30
|
when 'CLASS_STATE'
|
30
31
|
if action.key?(:set_state)
|
31
32
|
action[:set_state]
|
32
33
|
else
|
33
|
-
new_state =
|
34
|
+
new_state = prev_state.dup # make a copy of state
|
34
35
|
if action.key?(:collected)
|
35
36
|
action[:collected].each do |act|
|
36
37
|
new_state[act[:class]] = {} unless new_state.key?(act[:class])
|
37
|
-
new_state[act[:class]].merge!(act[:
|
38
|
+
new_state[act[:class]].merge!(act[:state])
|
38
39
|
end
|
39
40
|
else
|
40
41
|
new_state[action[:class]] = {} unless new_state.key?(action[:class])
|
41
|
-
new_state[action[:class]].merge!(action[:
|
42
|
+
new_state[action[:class]].merge!(action[:state])
|
42
43
|
end
|
43
44
|
new_state
|
44
45
|
end
|
@@ -46,8 +47,9 @@ module Redux
|
|
46
47
|
prev_state.nil? ? {} : prev_state
|
47
48
|
end
|
48
49
|
end
|
49
|
-
|
50
|
-
Redux::Store.
|
50
|
+
|
51
|
+
::Redux::Store.preloaded_state_merge!(application_state: {}, class_state: {})
|
52
|
+
::Redux::Store.add_reducers(application_state: app_reducer, class_state: class_reducer)
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
data/lib/isomorfeus-redux.rb
CHANGED
@@ -1,35 +1,23 @@
|
|
1
1
|
require 'opal'
|
2
|
-
require 'isomorfeus
|
3
|
-
require 'isomorfeus/
|
2
|
+
require 'isomorfeus-transport'
|
3
|
+
require 'isomorfeus/redux/config'
|
4
|
+
require 'redux/store'
|
5
|
+
require 'isomorfeus/redux_reducers'
|
6
|
+
require 'isomorfeus/browser_store_api'
|
7
|
+
require 'local_store'
|
8
|
+
require 'session_store'
|
9
|
+
require 'app_state'
|
4
10
|
|
5
|
-
|
6
|
-
require 'native'
|
7
|
-
require 'promise'
|
8
|
-
require 'securerandom'
|
9
|
-
require 'isomorfeus/core_ext/hash/deep_merge'
|
10
|
-
require 'redux'
|
11
|
-
require 'redux/store'
|
12
|
-
require 'redux/reducers'
|
13
|
-
require 'isomorfeus/redux/config'
|
14
|
-
require 'isomorfeus/browser_store_api'
|
15
|
-
require 'local_store'
|
16
|
-
require 'session_store'
|
17
|
-
require 'app_store'
|
11
|
+
Isomorfeus::ReduxReducers.add_application_reducers
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
else
|
22
|
-
opal_path = Gem::Specification.find_by_name('opal').full_gem_path
|
23
|
-
promise_path = File.join(opal_path, 'stdlib', 'promise.rb')
|
24
|
-
require promise_path
|
25
|
-
require 'redux/version'
|
26
|
-
|
27
|
-
Opal.append_path(__dir__.untaint)
|
28
|
-
|
29
|
-
require 'isomorfeus-speednode'
|
30
|
-
Isomorfeus.node_paths << File.expand_path(File.join(File.dirname(__FILE__), '..', 'node_modules'))
|
31
|
-
|
13
|
+
if RUBY_ENGINE != 'opal'
|
14
|
+
require 'isomorfeus/redux/version'
|
32
15
|
require 'isomorfeus-asset-manager'
|
33
|
-
require 'isomorfeus/
|
34
|
-
Isomorfeus::
|
16
|
+
require 'isomorfeus/redux_imports'
|
17
|
+
Isomorfeus::ReduxImports.add
|
18
|
+
|
19
|
+
require 'isomorfeus/redux/handler'
|
20
|
+
|
21
|
+
require 'iso_opal'
|
22
|
+
Opal.append_path(__dir__.untaint) unless IsoOpal.paths.include?(__dir__.untaint)
|
35
23
|
end
|
data/lib/local_store.rb
CHANGED
@@ -2,40 +2,37 @@ class LocalStore
|
|
2
2
|
extend Isomorfeus::BrowserStoreApi
|
3
3
|
|
4
4
|
class << self
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
`Opal.global.localStorage.setItem(key, value)`
|
11
|
-
notify_subscribers
|
12
|
-
value
|
13
|
-
else
|
14
|
-
# check store for value
|
15
|
-
value = `Opal.global.localStorage.getItem(key)`
|
16
|
-
return value if value
|
17
|
-
end
|
5
|
+
if RUBY_ENGINE == 'opal'
|
6
|
+
def [](key)
|
7
|
+
value = `Opal.global.localStorage.getItem(key)`
|
8
|
+
return nil if `value == null`
|
9
|
+
value
|
18
10
|
end
|
19
|
-
# otherwise return nil
|
20
|
-
return nil
|
21
|
-
end
|
22
|
-
|
23
|
-
alias [] method_missing
|
24
|
-
alias []= method_missing
|
25
11
|
|
26
|
-
|
27
|
-
|
12
|
+
def []=(key, value)
|
13
|
+
`Opal.global.localStorage.setItem(key, value)`
|
14
|
+
notify_subscribers
|
15
|
+
value
|
16
|
+
end
|
28
17
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
18
|
+
def delete(key)
|
19
|
+
`Opal.global.localStorage.removeItem(key)`
|
20
|
+
notify_subscribers
|
21
|
+
nil
|
22
|
+
end
|
34
23
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
24
|
+
def clear
|
25
|
+
`Opal.global.localStorage.clear()`
|
26
|
+
notify_subscribers
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
else
|
30
|
+
def [](key); end
|
31
|
+
def []=(key, value); end
|
32
|
+
def delete(key); end
|
33
|
+
def clear; end
|
39
34
|
end
|
35
|
+
alias get []
|
36
|
+
alias set []=
|
40
37
|
end
|
41
38
|
end
|