isomorfeus-redux 4.0.0 → 4.0.1

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: 3f0fa508494a00cb6c953ec0660d5a25fcdfeeadfe860b521cc60568da02357d
4
- data.tar.gz: 7b318ed593527284d0e946067c278dceed3a4eaa0e8fbc0941b111c1f49d688a
3
+ metadata.gz: 316eff3b0ae68f2c49026abe7bb2176e56d584f33e84b4cbc249551d67ddffed
4
+ data.tar.gz: c85a2a6d5aab70b1103eff25e30b3fb37c3c3df007f70d611fdc99994ad38406
5
5
  SHA512:
6
- metadata.gz: fb7e38b768252ae140861adb4fe56afdec8b6e74704a710efec364eeaa168a849e07b66dad85b59bb4af5fbaa80d685064d27ecaedbe6abfb5b68fb027ba9d15
7
- data.tar.gz: 93e6ee7ae5bb629f0d480b71e87c96c49299102f37b41875e670911da5987619707ae1077d4e57abc4e508cbaa2d77fd2bc4f9b26f10d4c155fe09fab7d5879c
6
+ metadata.gz: 0f6ef180cd71de42683bc99fd017e83f868eb6ecd467b37cf8ee9c191c5b6df87b25c96afc58e50c710b61c0b03917719c38a29efb2302fc671e3abdee60c55b
7
+ data.tar.gz: 6503807aca972d4d3bc5f6e0a196cdd7bb2932305df9637ef8070228899c8c318c654475390954770f33c1beb2ce712b37adac4a8fe978a396f8320c90950026
@@ -1,5 +1,4 @@
1
1
  module Redux
2
-
3
2
  def self.create_store(reducer, preloaded_state = nil, enhancer = nil)
4
3
  Redux::Store.new(reducer, preloaded_state, enhancer)
5
4
  end
@@ -25,7 +24,7 @@ module Redux
25
24
  end
26
25
 
27
26
  def self.bind_action_creators(*args)
28
- dispatch = args.pop()
27
+ dispatch = args.pop
29
28
  `Redux.bindActionCreators(args, dispatch)`
30
29
  end
31
30
 
@@ -36,10 +35,85 @@ module Redux
36
35
  def self.create_reducer(&block)
37
36
  %x{
38
37
  return (function(previous_state, action) {
39
- var new_state = block.$call(Opal.Hash.$new(previous_state), Opal.Hash.$new(action));
40
- if (typeof new_state.$class === "function") { new_state = new_state.$to_n(); }
38
+ var previous_state_hash = Opal.Hash.$new(previous_state);
39
+ var new_state_hash = block.$call(previous_state_hash, Opal.Hash.$new(action));
40
+ if (previous_state_hash === new_state_hash) { return previous_state; }
41
+ if (typeof new_state.$class === "function") { return new_state.$to_n(); }
41
42
  return new_state;
42
43
  });
43
44
  }
44
45
  end
46
+
47
+ def self.delete_state_path(state, *path)
48
+ size = path.size - 1
49
+ set_state_path(state, *path[0..-2], nil)
50
+ (2...size).each do |i|
51
+ val = get_state_path(state, *path[0..-i])
52
+ break if val.keys.size > 1
53
+ set_state_path(state, *path[0..-i], nil)
54
+ end
55
+ end
56
+
57
+ def self.fetch_by_path(*path)
58
+ # get active redux component
59
+ # (There should be a better way to get the component)
60
+ %x{
61
+ var active_component = Opal.React.active_redux_component();
62
+ var current_state;
63
+ var final_data;
64
+ var path_last = path.length - 1;
65
+ if (path[path_last].constructor === Array) {
66
+ path[path_last] = JSON.stringify(path[path_last]);
67
+ }
68
+ if (active_component) {
69
+ // try to get data from component state or props or store
70
+ current_state = active_component.data_access()
71
+ if (current_state) {
72
+ final_data = path.reduce(function(prev, curr) { return prev && prev[curr]; }, current_state);
73
+ // if final data doesn't exist, its set to 'null', so nil or false are ok as final_data
74
+ if (final_data !== null && typeof final_data !== "undefined") { return final_data; }
75
+ }
76
+ } else {
77
+ // try to get data from store
78
+ current_state = 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, its set to 'null', so nil or false are ok as final_data
81
+ if (final_data !== null && typeof final_data !== "undefined") { return final_data; }
82
+ }
83
+ return null;
84
+ }
85
+ end
86
+
87
+ def self.get_state_path(state, *path)
88
+ path.inject(state) do |state_el, path_el|
89
+ if state_el.has_key?(path_el)
90
+ state_el[path_el]
91
+ else
92
+ return nil
93
+ end
94
+ end
95
+ end
96
+
97
+ def self.register_used_store_path(*path)
98
+ %x{
99
+ var active_component = Opal.React.active_redux_component();
100
+ if (active_component) { active_component.register_used_store_path(path); }
101
+ }
102
+ end
103
+
104
+ def self.set_state_path(state, *path, value)
105
+ last_el = path.last
106
+ path.inject(state) do |state_el, path_el|
107
+ if path_el == last_el
108
+ state_el[path_el] = value
109
+ state_el[path_el]
110
+ elsif !state_el.has_key?(path_el)
111
+ state_el[path_el] = {}
112
+ state_el[path_el]
113
+ else
114
+ state_el[path_el]
115
+ end
116
+ end
117
+ nil
118
+ end
45
119
  end
@@ -1,3 +1,3 @@
1
1
  module Redux
2
- VERSION = '4.0.0'
2
+ VERSION = '4.0.1'
3
3
  end
@@ -2,6 +2,9 @@
2
2
 
3
3
  Redux for Opal Ruby.
4
4
 
5
+ ### Community and Support
6
+ At the [Isomorfeus Framework Project](http://isomorfeus.com)
7
+
5
8
  ## Versioning
6
9
  isomorfeus-redux version follows the Redux version which features and API it implements.
7
10
  Isomorfeus-redux 4.0.x implements features and the API of Redux 4.0 and should be used with Redux4.0
@@ -20,6 +23,21 @@ and to your client code add:
20
23
  ```ruby
21
24
  require 'isomorfeus-redux'
22
25
  ```
26
+
27
+ ### Dependencies
28
+
29
+ For full functionality the following are required:
30
+ - [Opal ES6 import export](https://github.com/opal/opal/pull/1832)
31
+ - [Opal Webpack Loader](https://github.com/janbiedermann/opal-webpack-loader)
32
+ - [Opal Autoloader](https://github.com/janbiedermann/opal-autoloader)
33
+
34
+ For the Gemfile:
35
+ ```ruby
36
+ gem 'opal', github: 'janbiedermann/opal', branch: 'es6_import_export'
37
+ gem 'opal-webpack-loader', '~> 0.3.7'
38
+ gem 'opal-autoloader', '~> 0.0.3'
39
+ ```
40
+
23
41
  ## Usage
24
42
  Because isomorfeus-redux follows closely the Redux principles/implementation/API and Documentation, most things of the official Redux documentation
25
43
  apply, but in the Ruby way, see:
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.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-29 00:00:00.000000000 Z
11
+ date: 2019-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.11.0
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: 0.12.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.11.0
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: 0.12.0
33
27
  description: Use a global store and write reducers for it in Opal Ruby.
34
28
  email:
35
29
  - jan@kursator.com
@@ -37,14 +31,12 @@ executables: []
37
31
  extensions: []
38
32
  extra_rdoc_files: []
39
33
  files:
40
- - Gemfile
41
- - README.md
42
- - isomorfeus-redux.gemspec
43
34
  - lib/isomorfeus-redux.rb
44
35
  - lib/isomorfeus/promise.rb
45
36
  - lib/redux.rb
46
37
  - lib/redux/store.rb
47
38
  - lib/redux/version.rb
39
+ - readme.md
48
40
  homepage: http://isomorfeus.com
49
41
  licenses:
50
42
  - MIT
@@ -64,8 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
56
  - !ruby/object:Gem::Version
65
57
  version: '0'
66
58
  requirements: []
67
- rubyforge_project:
68
- rubygems_version: 2.7.6
59
+ rubygems_version: 3.0.3
69
60
  signing_key:
70
61
  specification_version: 4
71
62
  summary: Redux for Opal Ruby.
data/Gemfile DELETED
@@ -1 +0,0 @@
1
- gemspec
@@ -1,20 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require_relative 'lib/redux/version.rb'
3
-
4
- Gem::Specification.new do |s|
5
- s.name = 'isomorfeus-redux'
6
- s.version = Redux::VERSION
7
-
8
- s.authors = ['Jan Biedermann']
9
- s.email = ['jan@kursator.com']
10
- s.homepage = 'http://isomorfeus.com'
11
- s.summary = 'Redux for Opal Ruby.'
12
- s.license = 'MIT'
13
- s.description = 'Use a global store and write reducers for it in Opal Ruby.'
14
-
15
- s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(gemfiles|s)/}) }
16
- # s.test_files = `git ls-files -- {test,s,features}/*`.split("\n")
17
- s.require_paths = ['lib']
18
-
19
- s.add_dependency 'opal', '>= 0.11.0', '< 0.12.0'
20
- end