rdux 0.8.0 → 0.9.1
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 +30 -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: fb70d8633e88f42179223f60bfe5634273591875f0e3d104fb076128af8811ba
|
4
|
+
data.tar.gz: 375487c3f51b78803b9d610877edb5e5fcec70918e86e376cf2601188a9e4358
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fbd330495ba4b140f828dc2e5184e27f4abd653c9e8d314d8a576c4612294c8baca8aceeeeccdab1e8be184a566544daaf1a75bc2dab2f1bba1801aab7f11cd
|
7
|
+
data.tar.gz: da3820133a5d277e1b5a20eee3876efb13e7cd434105585a3b2da5a014062072e17a77a93b35f35bb601d1f7d6c30dc4b930adb9e0f56e99aaeb358f1b9629e8
|
data/lib/rdux/version.rb
CHANGED
data/lib/rdux.rb
CHANGED
@@ -9,9 +9,13 @@ 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
|
+
res.after_save&.call(res.action)
|
18
|
+
res
|
15
19
|
end
|
16
20
|
|
17
21
|
alias perform dispatch
|
@@ -21,14 +25,18 @@ module Rdux
|
|
21
25
|
def call_call_or_up_on_action(action, opts)
|
22
26
|
res = action.call(opts)
|
23
27
|
if res
|
24
|
-
res
|
25
|
-
res
|
26
|
-
else
|
27
|
-
res = action.up(opts)
|
28
|
+
no_down(res)
|
29
|
+
return res
|
28
30
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
|
32
|
+
action.up(opts)
|
33
|
+
rescue StandardError => e
|
34
|
+
handle_exception(e, action)
|
35
|
+
end
|
36
|
+
|
37
|
+
def no_down(res)
|
38
|
+
res[:val] ||= res.down_payload
|
39
|
+
res.down_payload = nil
|
32
40
|
end
|
33
41
|
|
34
42
|
def assign_and_persist(res, action)
|
@@ -71,5 +79,18 @@ module Rdux
|
|
71
79
|
action.up_payload_unsanitized = action.up_payload if action.up_payload_sanitized
|
72
80
|
action.up_payload = up_payload_sanitized
|
73
81
|
end
|
82
|
+
|
83
|
+
def handle_exception(exc, action)
|
84
|
+
failed_action = action.to_failed_action
|
85
|
+
failed_action.up_result = {
|
86
|
+
'Exception' => {
|
87
|
+
class: exc.class.name,
|
88
|
+
message: exc.message
|
89
|
+
}
|
90
|
+
}
|
91
|
+
failed_action.save!
|
92
|
+
action.destroy
|
93
|
+
raise exc
|
94
|
+
end
|
74
95
|
end
|
75
96
|
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.1
|
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
|