grand_central 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 6c0e9a7148ac9f9b9e5b20cc9274a586b9afe8e0
4
- data.tar.gz: a7086f1e94374a7a9d80e8392387fcabde4fc414
3
+ metadata.gz: d04e898aad39b554216bebfb1d214bb2e9d1980a
4
+ data.tar.gz: c6acec83ffd46a28b3e26370bf00a435fe617afe
5
5
  SHA512:
6
- metadata.gz: 4a76db401fa74f3ea0d82f0ec85f191407098b8c8317c74fb5d08f6b91805d0e40f7140daec007e41d58a6cfd5b689d7fbadb99a82b645e843dd7cde791f91c1
7
- data.tar.gz: dc22db5f648f0c447a60840bc397907c71000f384f9b18e5ba7d387168bd09169a66dee9782058866bb53d10b306ac52f523a35a2a896490536695dada069fe1
6
+ metadata.gz: 7878e1b8c46119044802db1ddd626931d2428008cbbda25190464e8a26a95f5ce35884d5640b776f0c7736196ed0f32397c251765fb855a1aec48f0c663a67de
7
+ data.tar.gz: c088494688d9c046b14db97c2f0482a171eeddb76eb23d7e95feae66843e3654fbe334734f663478f6f141985901e598734c1a329c7d43c0557088e2d9620b02
@@ -11,9 +11,7 @@ module GrandCentral
11
11
  def dispatch action
12
12
  old_state = state
13
13
  @state = @reducer.call state, action
14
- @dispatch_callbacks.each do |callback|
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
@@ -1,3 +1,3 @@
1
1
  module GrandCentral
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  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
@@ -1,6 +1,7 @@
1
1
  require "grand_central/version"
2
2
  require "grand_central/store"
3
3
  require "grand_central/action"
4
+ require "opal"
4
5
 
5
6
  module GrandCentral
6
7
  end
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.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-09-06 00:00:00.000000000 Z
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: {}