rubidux 0.0.7 → 0.0.8
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/Gemfile +1 -1
- data/LICENSE.txt +21 -0
- data/README.md +8 -6
- data/Rakefile +9 -1
- data/lib/rubidux/middleware.rb +1 -1
- data/lib/rubidux/reducer.rb +6 -2
- data/lib/rubidux/store.rb +13 -5
- data/lib/rubidux/version.rb +1 -1
- data/rubidux.gemspec +5 -2
- metadata +38 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 852ffb26464ab705f8939b49a69668ab9a91568c
|
4
|
+
data.tar.gz: b4547d84ddae4276a32a68f3cfff4988f4873421
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a8431da9e841771a7f178bf0badbf31072939fbb80f37ad204e9d515a60ec221324de296ca04103e0f52d7cfce40a9f05df75f9d0a247548dc44e15df233c67
|
7
|
+
data.tar.gz: 93a145c9d686f3761cdf21cb75bf04fd9b6a8e6ac07bc7e220e08c5dbae8a9605b5d87cef9e1effad95014b6ebfa68de0a6af2536d7c98d2816844f9ffaef6f5
|
data/Gemfile
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Juin Chiu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rubidux
|
2
2
|
|
3
|
-
Rubidux is a tiny
|
3
|
+
Rubidux is a tiny state management library inspired by [Redux](https://github.com/reactjs/redux)
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -25,7 +25,7 @@ Reducers are functions that take state and action as arguments and return a new
|
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
r1 = -> (state, action) {
|
28
|
-
state
|
28
|
+
state ||= { a: 0, b: 0 }
|
29
29
|
|
30
30
|
case action[:type]
|
31
31
|
when 'a_plus_one'
|
@@ -38,7 +38,7 @@ r1 = -> (state, action) {
|
|
38
38
|
}
|
39
39
|
|
40
40
|
r2 = -> (state, action) {
|
41
|
-
state
|
41
|
+
state ||= { c: 0, d: 0 }
|
42
42
|
|
43
43
|
case action[:type]
|
44
44
|
when 'c_plus_one'
|
@@ -61,12 +61,14 @@ Rubidux::Reducer.combine(r1: r1, r2: r2)
|
|
61
61
|
You can make a middleware via `init`:
|
62
62
|
|
63
63
|
```ruby
|
64
|
-
m1 = Rubidux::Middleware.init { |action, **middleware_api|
|
65
|
-
puts "#{action} in middleware 1"
|
64
|
+
m1 = Rubidux::Middleware.init { |_next, action, **middleware_api|
|
65
|
+
puts "#{action} in middleware 1"
|
66
|
+
_next.(action)
|
66
67
|
}
|
67
68
|
|
68
|
-
m2 = Rubidux::Middleware.init { |action, **middleware_api|
|
69
|
+
m2 = Rubidux::Middleware.init { |_next, action, **middleware_api|
|
69
70
|
puts "#{middleware_api[:get_state].()} in middleware 2"
|
71
|
+
_next.(action)
|
70
72
|
}
|
71
73
|
```
|
72
74
|
|
data/Rakefile
CHANGED
data/lib/rubidux/middleware.rb
CHANGED
data/lib/rubidux/reducer.rb
CHANGED
@@ -2,8 +2,12 @@ module Rubidux
|
|
2
2
|
class Reducer
|
3
3
|
def self.combine(**reducers)
|
4
4
|
-> (state, action) {
|
5
|
-
state
|
6
|
-
|
5
|
+
state ||= {}
|
6
|
+
reducers.
|
7
|
+
lazy.
|
8
|
+
select { |key, reducer| reducer.is_a? Proc }.
|
9
|
+
map { |key, reducer| [key, reducer.(state[key], action)] }.
|
10
|
+
to_h
|
7
11
|
}
|
8
12
|
end
|
9
13
|
end
|
data/lib/rubidux/store.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Rubidux
|
2
2
|
class Store
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
attr_reader :state
|
4
|
+
attr_reader :reducer
|
5
|
+
attr_reader :listeners
|
6
|
+
attr_reader :dispatch
|
7
|
+
attr_reader :subscribe
|
8
8
|
|
9
9
|
def initialize(reducer, preload_state, enhancer = nil)
|
10
10
|
raise ArgumentError.new("Expect reducer to be a Proc.") unless reducer.is_a? Proc
|
@@ -36,4 +36,12 @@ module Rubidux
|
|
36
36
|
}
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
attr_writer :state
|
43
|
+
attr_writer :reducer
|
44
|
+
attr_writer :listeners
|
45
|
+
attr_writer :dispatch
|
46
|
+
attr_writer :subscribe
|
39
47
|
end
|
data/lib/rubidux/version.rb
CHANGED
data/rubidux.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.summary = "A tiny ruby framework inspired by Redux"
|
13
13
|
spec.description = "A tiny ruby framework inspired by Redux"
|
14
14
|
spec.homepage = "https://github.com/davidjuin0519/rubidux"
|
15
|
+
spec.license = "MIT"
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
18
|
f.match(%r{^(test|spec|features)/})
|
@@ -20,6 +21,8 @@ Gem::Specification.new do |spec|
|
|
20
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
22
|
spec.require_paths = ["lib"]
|
22
23
|
|
23
|
-
spec.add_development_dependency "bundler", "
|
24
|
-
spec.add_development_dependency "rake", "
|
24
|
+
spec.add_development_dependency "bundler", ">= 1.13"
|
25
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
26
|
+
spec.add_development_dependency "minitest", ">= 5.8"
|
27
|
+
spec.add_development_dependency "minitest-reporters", ">= 1.1"
|
25
28
|
end
|
metadata
CHANGED
@@ -1,43 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubidux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juin Chiu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.13'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.13'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-reporters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.1'
|
41
69
|
description: A tiny ruby framework inspired by Redux
|
42
70
|
email:
|
43
71
|
- davidjuin0519@gmail.com
|
@@ -47,6 +75,7 @@ extra_rdoc_files: []
|
|
47
75
|
files:
|
48
76
|
- ".gitignore"
|
49
77
|
- Gemfile
|
78
|
+
- LICENSE.txt
|
50
79
|
- README.md
|
51
80
|
- Rakefile
|
52
81
|
- bin/console
|
@@ -59,7 +88,8 @@ files:
|
|
59
88
|
- lib/rubidux/version.rb
|
60
89
|
- rubidux.gemspec
|
61
90
|
homepage: https://github.com/davidjuin0519/rubidux
|
62
|
-
licenses:
|
91
|
+
licenses:
|
92
|
+
- MIT
|
63
93
|
metadata: {}
|
64
94
|
post_install_message:
|
65
95
|
rdoc_options: []
|
@@ -77,9 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
107
|
version: '0'
|
78
108
|
requirements: []
|
79
109
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.5.1
|
81
111
|
signing_key:
|
82
112
|
specification_version: 4
|
83
113
|
summary: A tiny ruby framework inspired by Redux
|
84
114
|
test_files: []
|
85
|
-
has_rdoc:
|