grand_central 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/grand_central/store.rb +7 -3
- data/lib/grand_central/version.rb +1 -1
- data/lib/grand_central/versioned_store.rb +35 -0
- data/lib/grand_central.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d04e898aad39b554216bebfb1d214bb2e9d1980a
|
4
|
+
data.tar.gz: c6acec83ffd46a28b3e26370bf00a435fe617afe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7878e1b8c46119044802db1ddd626931d2428008cbbda25190464e8a26a95f5ce35884d5640b776f0c7736196ed0f32397c251765fb855a1aec48f0c663a67de
|
7
|
+
data.tar.gz: c088494688d9c046b14db97c2f0482a171eeddb76eb23d7e95feae66843e3654fbe334734f663478f6f141985901e598734c1a329c7d43c0557088e2d9620b02
|
data/lib/grand_central/store.rb
CHANGED
@@ -11,9 +11,7 @@ module GrandCentral
|
|
11
11
|
def dispatch action
|
12
12
|
old_state = state
|
13
13
|
@state = @reducer.call state, action
|
14
|
-
|
15
|
-
callback.call old_state, state
|
16
|
-
end
|
14
|
+
run_callbacks old_state, state
|
17
15
|
self
|
18
16
|
end
|
19
17
|
|
@@ -21,5 +19,11 @@ module GrandCentral
|
|
21
19
|
@dispatch_callbacks << block
|
22
20
|
self
|
23
21
|
end
|
22
|
+
|
23
|
+
def run_callbacks old_state, new_state
|
24
|
+
@dispatch_callbacks.each do |callback|
|
25
|
+
callback.call old_state, new_state
|
26
|
+
end
|
27
|
+
end
|
24
28
|
end
|
25
29
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'grand_central/store'
|
2
|
+
|
3
|
+
module GrandCentral
|
4
|
+
class VersionedStore < Store
|
5
|
+
def initialize *args
|
6
|
+
super
|
7
|
+
@rollback_versions = []
|
8
|
+
@redo_versions = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def dispatch *args
|
12
|
+
@rollback_versions << state
|
13
|
+
@redo_versions.clear
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def rollback
|
18
|
+
unless @rollback_versions.empty?
|
19
|
+
@redo_versions << (old_state = state)
|
20
|
+
@state = @rollback_versions.pop
|
21
|
+
end
|
22
|
+
|
23
|
+
run_callbacks old_state, state
|
24
|
+
end
|
25
|
+
|
26
|
+
def redo
|
27
|
+
unless @redo_versions.empty?
|
28
|
+
@rollback_versions << (old_state = state)
|
29
|
+
@state = @redo_versions.pop
|
30
|
+
end
|
31
|
+
|
32
|
+
run_callbacks old_state, state
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/grand_central.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grand_central
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Gaskins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/grand_central/action.rb
|
88
88
|
- lib/grand_central/store.rb
|
89
89
|
- lib/grand_central/version.rb
|
90
|
+
- lib/grand_central/versioned_store.rb
|
90
91
|
homepage: https://github.com/clearwater-rb/grand_central
|
91
92
|
licenses: []
|
92
93
|
metadata: {}
|