isomorfeus-redux 4.1.13 → 4.1.14
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/lib/redux/store.rb +81 -72
- data/lib/redux/version.rb +1 -1
- data/lib/redux.rb +94 -88
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 025b8912245201aa017694533af72e872c0fab88ddfb92b5e635063b54c755b4
|
4
|
+
data.tar.gz: 27c35a6d959b591a4466761d60a86bc5bb39b8ad1fbeeba8fcb2b8ba69a91459
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f57f256c46df5c13c3ed94cbf4cb5649186130eeb9b9fa9fa021adfadc730e9a737a90a0dab41857be3f78db7060b30c874c7c8f64385d1d04e179d158aec18e
|
7
|
+
data.tar.gz: 4cb517c3356c24f4b76186a14d189e4f169dfeb6f804fc70c40324e206abeaf920eecf96b7591ace34d5d4abfa52e2b6701ea897ae934e45a8750cafa6ea65b6
|
data/lib/redux/store.rb
CHANGED
@@ -2,99 +2,103 @@ module Redux
|
|
2
2
|
class Store
|
3
3
|
include Native::Wrapper
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
class << self
|
6
|
+
def add_middleware(middleware)
|
7
|
+
if Isomorfeus.store
|
8
|
+
`console.warning("Adding middleware after Store initialization may have side effects! Saving state and initializing new store with restored state!")`
|
9
|
+
middlewares << middleware
|
10
|
+
preloaded_state = Isomorfeus.store.get_state
|
11
|
+
init!
|
12
|
+
else
|
13
|
+
middlewares << middleware
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
def add_reducer(reducer)
|
18
|
+
if Isomorfeus.store
|
19
|
+
# if the store has been initalized already, add the reducer to the instance
|
20
|
+
Isomorfeus.store.add_reducer(reducer)
|
21
|
+
else
|
22
|
+
# otherwise just add it to the reducers, so that they will be used when initializing the store
|
23
|
+
preloaded_state[reducer.keys.first] = {} unless preloaded_state.key?(reducer.keys.first)
|
24
|
+
reducers.merge!(reducer)
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
def add_reducers(new_reducers)
|
29
|
+
if Isomorfeus.store
|
30
|
+
# if the store has been initalized already, add the reducer to the instance
|
31
|
+
Isomorfeus.store.add_reducers(new_reducers)
|
32
|
+
else
|
33
|
+
# otherwise just add it to the reducers, so that they will be used when initializing the store
|
34
|
+
new_reducers.each do |key, value|
|
35
|
+
add_reducer(key => value)
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
37
|
-
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
# called from Isomorfeus.init
|
41
|
+
def init!
|
42
|
+
next_reducer = Redux.combine_reducers(@reducers)
|
43
|
+
if middlewares.any?
|
44
|
+
enhancer = Redux.apply_middleware(middlewares)
|
45
|
+
Redux::Store.new(next_reducer, preloaded_state, enhancer)
|
46
|
+
else
|
47
|
+
Redux::Store.new(next_reducer, preloaded_state)
|
48
|
+
end
|
47
49
|
end
|
48
|
-
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def middlewares
|
52
|
+
@middlewares ||= []
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
def preloaded_state_merge!(ruby_hash)
|
56
|
+
preloaded_state.merge!(ruby_hash)
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def preloaded_state
|
60
|
+
@preloaded_state ||= {}
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
def preloaded_state=(ruby_hash)
|
64
|
+
@preloaded_state = ruby_hash
|
65
|
+
end
|
65
66
|
|
66
|
-
|
67
|
-
|
67
|
+
def reducers
|
68
|
+
@reducers ||= {}
|
69
|
+
end
|
68
70
|
end
|
69
71
|
|
70
|
-
def initialize(reducer, preloaded_state =
|
72
|
+
def initialize(reducer, preloaded_state = nil, enhancer = nil)
|
71
73
|
@deferred_actions = {}
|
72
74
|
@deferred_dispatcher = nil
|
73
75
|
@last_dispatch_time = Time.now
|
74
76
|
%x{
|
75
|
-
var
|
76
|
-
var
|
77
|
-
if (
|
78
|
-
|
79
|
-
|
77
|
+
var ogre = Opal.global.Redux;
|
78
|
+
var compose = (typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || ogre.compose;
|
79
|
+
if (enhancer == nil) { enhancer = null; }
|
80
|
+
if (typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION__) {
|
81
|
+
var devext_enhance = window.__REDUX_DEVTOOLS_EXTENSION__();
|
82
|
+
if (enhancer) { enhancer = compose([enhancer, devext_enhance]); }
|
83
|
+
else { enhancer = devext_enhance; }
|
84
|
+
}
|
85
|
+
if (preloaded_state == nil) {
|
86
|
+
preloaded_state = null;
|
87
|
+
} else if (typeof preloaded_state.$class === "function" && preloaded_state.$class() == "Hash") {
|
80
88
|
if (preloaded_state.$size() == 0) {
|
81
|
-
|
89
|
+
preloaded_state = null;
|
82
90
|
} else {
|
83
|
-
|
91
|
+
preloaded_state = preloaded_state.$to_n();
|
84
92
|
}
|
85
|
-
} else if (preloaded_state == nil) {
|
86
|
-
real_preloaded_state = null;
|
87
|
-
} else {
|
88
|
-
real_preloaded_state = preloaded_state;
|
89
93
|
}
|
90
|
-
if (enhancer &&
|
91
|
-
this.native =
|
92
|
-
} else if (
|
93
|
-
this.native =
|
94
|
+
if (enhancer && preloaded_state) {
|
95
|
+
this.native = ogre.createStore(reducer, preloaded_state, enhancer);
|
96
|
+
} else if (preloaded_state) {
|
97
|
+
this.native = ogre.createStore(reducer, preloaded_state);
|
94
98
|
} else if (enhancer) {
|
95
|
-
this.native =
|
99
|
+
this.native = ogre.createStore(reducer, enhancer);
|
96
100
|
} else {
|
97
|
-
this.native =
|
101
|
+
this.native = ogre.createStore(reducer);
|
98
102
|
}
|
99
103
|
}
|
100
104
|
end
|
@@ -114,15 +118,20 @@ module Redux
|
|
114
118
|
def dispatch(action)
|
115
119
|
%x{
|
116
120
|
if (typeof action.$class === "function" && action.$class() == "Hash") {
|
117
|
-
|
118
|
-
} else {
|
119
|
-
this.native.dispatch(action);
|
121
|
+
action = action.$to_n();
|
120
122
|
}
|
123
|
+
this.native.dispatch(action);
|
121
124
|
}
|
122
125
|
end
|
123
126
|
|
124
127
|
def get_state
|
125
|
-
|
128
|
+
%x{
|
129
|
+
let res = this.native.getState();
|
130
|
+
if (typeof(res) === 'object' && !Array.isArray(res) && res !== null) {
|
131
|
+
return Opal.Hash.$new(res);
|
132
|
+
}
|
133
|
+
return res;
|
134
|
+
}
|
126
135
|
end
|
127
136
|
|
128
137
|
def collect_and_defer_dispatch(action)
|
data/lib/redux/version.rb
CHANGED
data/lib/redux.rb
CHANGED
@@ -1,112 +1,118 @@
|
|
1
1
|
module Redux
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class << self
|
3
|
+
def create_store(reducer, preloaded_state = nil, enhancer = nil)
|
4
|
+
Redux::Store.new(reducer, preloaded_state, enhancer)
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
real_reducers = reducers;
|
7
|
+
def combine_reducers(reducers)
|
8
|
+
%x{
|
9
|
+
if (typeof reducers.$to_n === "function") {
|
10
|
+
reducers = reducers.$to_n();
|
11
|
+
}
|
12
|
+
return Opal.global.Redux.combineReducers(reducers);
|
13
13
|
}
|
14
|
-
|
15
|
-
}
|
16
|
-
end
|
14
|
+
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
def apply_middleware(*middlewares)
|
17
|
+
if middlewares.size == 1
|
18
|
+
`Opal.global.Redux.applyMiddleware.apply(null, middlewares[0])`
|
19
|
+
else
|
20
|
+
`Opal.global.Redux.applyMiddleware.apply(null, middlewares)`
|
21
|
+
end
|
23
22
|
end
|
24
|
-
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
def bind_action_creators(*args)
|
25
|
+
dispatch = args.pop
|
26
|
+
`Opal.global.Redux.bindActionCreators(args, dispatch)`
|
27
|
+
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
def compose(*functions)
|
30
|
+
`Opal.global.Redux.compose(functions)`
|
31
|
+
end
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
33
|
+
def create_reducer(&block)
|
34
|
+
%x{
|
35
|
+
return function(previous_state, action) {
|
36
|
+
let state = null;
|
37
|
+
if (previous_state === null || typeof(previous_state) === 'undefined') { state = nil; }
|
38
|
+
else if (typeof(previous_state) === 'object' && !Array.isArray(previous_state)) {
|
39
|
+
state = Opal.Hash.$new(previous_state);
|
40
|
+
} else { state = previous_state; }
|
41
|
+
var new_state = block.$call(state, Opal.Hash.$new(action));
|
42
|
+
if (typeof(previous_state) === 'undefined' || previous_state === null) {
|
43
|
+
if (typeof(new_state.$to_n) === "function") { return new_state.$to_n(); }
|
44
|
+
return new_state;
|
45
|
+
}
|
46
|
+
if (state === new_state) { return previous_state; }
|
47
|
+
if (typeof(new_state.$to_n) === "function") { return new_state.$to_n(); }
|
48
|
+
return previous_state;
|
49
|
+
};
|
50
|
+
}
|
51
|
+
end
|
47
52
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
def delete_state_path(state, *path)
|
54
|
+
size = path.size - 1
|
55
|
+
set_state_path(state, *path[0..-2], nil)
|
56
|
+
(2...size).each do |i|
|
57
|
+
val = get_state_path(state, *path[0..-i])
|
58
|
+
break if val.keys.size > 1
|
59
|
+
set_state_path(state, *path[0..-i], nil)
|
60
|
+
end
|
55
61
|
end
|
56
|
-
end
|
57
62
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
def fetch_by_path(*path)
|
64
|
+
# get active redux component
|
65
|
+
%x{
|
66
|
+
var active_component = Opal.Preact.active_redux_component();
|
67
|
+
var current_state;
|
68
|
+
var final_data;
|
69
|
+
var path_last = path.length - 1;
|
70
|
+
if (path[path_last].constructor === Array) {
|
71
|
+
path[path_last] = JSON.stringify(path[path_last]);
|
72
|
+
}
|
73
|
+
if (active_component) {
|
74
|
+
// try to get data from component state or props or store
|
75
|
+
current_state = active_component.data_access()
|
76
|
+
if (current_state) {
|
77
|
+
final_data = path.reduce(function(prev, curr) { return prev && prev[curr]; }, current_state);
|
78
|
+
// if final data doesn't exist, 'null' is returned, so nil or false are ok as final_data
|
79
|
+
if (final_data !== null && typeof final_data !== "undefined") { return final_data; }
|
80
|
+
}
|
81
|
+
} else {
|
82
|
+
// try to get data from store
|
83
|
+
current_state = Opal.Isomorfeus.store.native.getState();
|
72
84
|
final_data = path.reduce(function(prev, curr) { return prev && prev[curr]; }, current_state);
|
73
85
|
// if final data doesn't exist, 'null' is returned, so nil or false are ok as final_data
|
74
86
|
if (final_data !== null && typeof final_data !== "undefined") { return final_data; }
|
75
87
|
}
|
76
|
-
|
77
|
-
// try to get data from store
|
78
|
-
current_state = Opal.Isomorfeus.store.native.getState();
|
79
|
-
final_data = path.reduce(function(prev, curr) { return prev && prev[curr]; }, current_state);
|
80
|
-
// if final data doesn't exist, 'null' is returned, so nil or false are ok as final_data
|
81
|
-
if (final_data !== null && typeof final_data !== "undefined") { return final_data; }
|
88
|
+
return null;
|
82
89
|
}
|
83
|
-
|
84
|
-
}
|
85
|
-
end
|
90
|
+
end
|
86
91
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
92
|
+
def get_state_path(state, *path)
|
93
|
+
path.inject(state) do |state_el, path_el|
|
94
|
+
if state_el.key?(path_el)
|
95
|
+
state_el[path_el]
|
96
|
+
else
|
97
|
+
return nil
|
98
|
+
end
|
93
99
|
end
|
94
100
|
end
|
95
|
-
end
|
96
101
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
102
|
+
def set_state_path(state, *path, value)
|
103
|
+
last_el = path.last
|
104
|
+
path.inject(state) do |state_el, path_el|
|
105
|
+
if path_el == last_el
|
106
|
+
state_el[path_el] = value
|
107
|
+
state_el[path_el]
|
108
|
+
elsif !state_el.key?(path_el)
|
109
|
+
state_el[path_el] = {}
|
110
|
+
state_el[path_el]
|
111
|
+
else
|
112
|
+
state_el[path_el]
|
113
|
+
end
|
108
114
|
end
|
115
|
+
nil
|
109
116
|
end
|
110
|
-
nil
|
111
117
|
end
|
112
118
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-redux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.14.
|
33
|
+
version: 0.14.9
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.14.
|
40
|
+
version: 0.14.9
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: isomorfeus-speednode
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.4.
|
47
|
+
version: 0.4.9
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.4.
|
54
|
+
version: 0.4.9
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|