rdux 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rdux/version.rb +1 -1
- data/lib/rdux.rb +32 -9
- metadata +2 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 273465473611ad7e7498f183191d7bb29b31a9e69af497ae0905cfd1a41d4781
|
4
|
+
data.tar.gz: 6e423cb95ef75e5d5a78288a14332bc8971ffa50cfe1c409d0b2997f17418cc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13de207f08f81118a33e7d4d849194a064d068f9b4a8b55f59f4bb5e6f7b47a66ac797982ecba2726cc558794e2aca22a3b15f5cc40f0ae6c1faae78ac710efe
|
7
|
+
data.tar.gz: 2ae59b96d2917a17891c9dc442040ae5068b1689926cc7495c6957615c95a6a0738c4b54a890057a7d426375335330dbbfd92b1d617c714981e2fb819d18d795
|
data/lib/rdux/version.rb
CHANGED
data/lib/rdux.rb
CHANGED
@@ -9,9 +9,15 @@ module Rdux
|
|
9
9
|
class << self
|
10
10
|
def dispatch(action_name, payload, opts = {}, meta: nil)
|
11
11
|
(opts[:ars] || {}).each { |k, v| payload["#{k}_id"] = v.id }
|
12
|
-
action = Action.
|
12
|
+
action = Action.new(name: action_name, up_payload: payload, meta:)
|
13
13
|
sanitize(action)
|
14
|
-
|
14
|
+
action.save!
|
15
|
+
res = call_call_or_up_on_action(action, opts)
|
16
|
+
assign_and_persist(res, action)
|
17
|
+
return res if res.ok == false
|
18
|
+
|
19
|
+
res.after_save&.call(res.action)
|
20
|
+
res
|
15
21
|
end
|
16
22
|
|
17
23
|
alias perform dispatch
|
@@ -21,14 +27,18 @@ module Rdux
|
|
21
27
|
def call_call_or_up_on_action(action, opts)
|
22
28
|
res = action.call(opts)
|
23
29
|
if res
|
24
|
-
res
|
25
|
-
res
|
26
|
-
else
|
27
|
-
res = action.up(opts)
|
30
|
+
no_down(res)
|
31
|
+
return res
|
28
32
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
|
34
|
+
action.up(opts)
|
35
|
+
rescue StandardError => e
|
36
|
+
handle_exception(e, action)
|
37
|
+
end
|
38
|
+
|
39
|
+
def no_down(res)
|
40
|
+
res[:val] ||= res.down_payload
|
41
|
+
res.down_payload = nil
|
32
42
|
end
|
33
43
|
|
34
44
|
def assign_and_persist(res, action)
|
@@ -71,5 +81,18 @@ module Rdux
|
|
71
81
|
action.up_payload_unsanitized = action.up_payload if action.up_payload_sanitized
|
72
82
|
action.up_payload = up_payload_sanitized
|
73
83
|
end
|
84
|
+
|
85
|
+
def handle_exception(exc, action)
|
86
|
+
failed_action = action.to_failed_action
|
87
|
+
failed_action.up_result = {
|
88
|
+
'Exception' => {
|
89
|
+
class: exc.class.name,
|
90
|
+
message: exc.message
|
91
|
+
}
|
92
|
+
}
|
93
|
+
failed_action.save!
|
94
|
+
action.destroy
|
95
|
+
raise exc
|
96
|
+
end
|
74
97
|
end
|
75
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zbigniew Humeniuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -88,9 +88,6 @@ dependencies:
|
|
88
88
|
version: 1.7.0
|
89
89
|
description: |
|
90
90
|
Write apps that are easy to test.
|
91
|
-
Rdux gives you a possibility to centralize your app's state modification logic (DB changes).
|
92
|
-
It does it via introducing a new architectural layer - actions.
|
93
|
-
Rdux enables powerful capabilities like undo/redo.
|
94
91
|
It makes it easy to trace when, where, why, and how your application's state changed.
|
95
92
|
email:
|
96
93
|
- hello@artofcode.co
|