rails_redhot 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 5be8aff1e9314532378f476e76fe310b84bfe386abe0ba18c33ec60820696d24
4
- data.tar.gz: f77470f8cec6b501c56fb0102e1b63242b0a11a4c453d4bbe3b3068b148b88fe
3
+ metadata.gz: 2bc4f84383d654009f5141fe5f0b2a7133d92a9cfa7cb8b95be9076430964928
4
+ data.tar.gz: e41024b7b92269e0d683d639928ce295f17ffff8f43541c6af803d1c96964353
5
5
  SHA512:
6
- metadata.gz: adbb2a15f3bcffe7b910b05217d5e564125915bd39710347b527a863462fb7bef50951358d0b2d31829994410abca865f88f183abe09e09e0aef8be56956a5bf
7
- data.tar.gz: 922d4eac6e294a8f25ac027eca82c457115884758fc785289c79867785618aa0f7a788975e5f66fcb4139bfd819cca39b4b263d6d7d8df989a6cdc03bec8f97d
6
+ metadata.gz: edbc120531cccaafad095636979183cf818505f7213a4bdc2957f47dc298905c039bbf9897efbf8ae23ba3bb055ae46c0c1132b5f78805a1fb4aa658ff0fc8d7
7
+ data.tar.gz: 58bab798b14f920c6e037d54afdc57b02ec44000dafacad5adab5c9c10c0bb792d17a340391f31157d793323d8c1e9742960fbf3c0b610e2b46f1cf8a5d68d96
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
- # 0.0.2 - December 10, 2021
1
+ # 0.1.1 - April 14, 2022
2
+
3
+ - Fix calling flatten! multiple times erased initial state
4
+ - Documentation updates
5
+ - Demo application: Use Ruby 3.1.2, Rails 7.0.2
6
+
7
+ # 0.1.0 - December 30, 2021
2
8
 
3
- [0.0.2]: https://github.com/easydatawarehousing/rails_redhot/compare/v0.0.1...v0.0.2
9
+ - Documentation updates
10
+ - Use Rails 7.0.0
11
+
12
+ # 0.0.2 - December 10, 2021
4
13
 
5
14
  - Added testset
6
15
  - Polished demo application
data/README.md CHANGED
@@ -1,34 +1,76 @@
1
1
  # RailsRedhot gem
2
- __REDux pattern for HOTwire == Redhot__
2
+ ### __REDux pattern for HOTwire == Redhot__
3
3
  Single page applications using redux (react) are very popular.
4
4
  And with good reason, redux makes maintaining the current state of the app easy.
5
5
  For instance when building some kind of editor, every action of the user is added
6
6
  to the redux store. All actions can be reduced to the determine the current state of
7
7
  the editor. Views are rendered using the current state.
8
- Or when building a search page for a webshop. Whenever the user selects a category
8
+ Or when building a complex search page for a webshop. Whenever the user selects a category
9
9
  or price range to filter on this can be an action for the redux store. If the user
10
10
  hits the back button the last action can be deleted and the current state
11
11
  regenerated by reducing all remaining actions. The user only sees the last filter
12
12
  being reverted to what it was before.
13
13
 
14
+ ### What is redux?
15
+ ```
16
+ It is a store containing a list of changes.
17
+ All changes combined determine the current view state through one or more reducer functions.
18
+ The current view state is also stored.
19
+ If a new change arrives it only needs to be applied to the current view state.
20
+ To undo a change apply all but the last action again to rebuild te view state.
21
+
22
+ For example a view contains a number counting the likes for an article.
23
+ There are two buttons: increase- and decrease the likes counter.
24
+ Clicking on a button adds an action to the store.
25
+ The action is passed on to all reducer functions,
26
+ each function passes the new computed state on to the next function:
27
+ - If the counter value is nil in the current state set it to zero
28
+ - If the action was 'increase' then increment the counter value
29
+ - If the action was 'decrease' then decrement the counter value
30
+ - If the counter value is lower than zero set it to zero
31
+ Save the new state in the store.
32
+ Render the view showing the updated counter value.
33
+ ```
34
+
35
+ ### What are the advantages of redux?
36
+ From the [redux website](https://redux.js.org/) (minus the part about plugins):
37
+ ```
38
+ Predictable
39
+ Redux helps you write applications that behave consistently,
40
+ run in different environments (client, server, and native)
41
+ and are easy to test.
42
+
43
+ Centralized
44
+ Centralizing your application's state and logic enables powerful capabilities
45
+ like undo/redo, state persistence, and much more.
46
+
47
+ Debuggable
48
+ The Redux DevTools make it easy to trace when, where, why
49
+ and how your application's state changed.
50
+ Redux's architecture lets you log changes, use 'time-travel debugging'
51
+ and even send complete error reports to a server.
52
+ ```
53
+
54
+ ### Remove complexity
14
55
  Sometimes the actions of the user in the frontend should be sent to a backend
15
56
  application. For instance when actions of multiple users should be kept in-sync.
16
- Often command-query-responsibility-separation (CQRS) is used for this purpose.
17
- These solutions can become very complex
57
+ In react applications command-query-responsibility-separation (CQRS) is often
58
+ used for this purpose. These solutions can become very complex
18
59
  ([example](https://medium.com/resolvejs/resolve-redux-backend-ebcfc79bbbea),
19
- scroll down a bit for a full example).
60
+ scroll down a bit for a full architecture picture).
20
61
 
21
62
  The Hotwire (Html Over The Wire) approach does an excellent job of removing the need
22
- to build single page apps. Hotwire will be the
63
+ to build single page apps. Hotwire is the
23
64
  [default tool](https://world.hey.com/dhh/the-time-is-right-for-hotwire-ecdb9b33)
24
65
  for frontend development in Rails 7.
25
66
  However when using hotwire the responsibilty of maintaining frontend state entirely
26
67
  falls to the backend application. So when building your editor or search page
27
- you need a way to keep track of that state. The redux (also known as flux) pattern
28
- is still very useful for this purpose.
68
+ you need a way to keep track of that state. The redux (also known as flux- or observer-)
69
+ pattern is very useful for this purpose.
29
70
 
71
+ ### Hotwire
30
72
  This gem aims to combine html-over-the-wire approach with the redux pattern to
31
- radically reduce complexity of the overall application.
73
+ radically reduce overall complexity of an application.
32
74
  (At least when compared to for instance react+cqrs application stacks.)
33
75
  Only four components are required:
34
76
 
@@ -39,9 +81,16 @@ Only four components are required:
39
81
  4. Reducers, a set of functions (provided by you) that translate actions to changes in
40
82
  state. The state can be used again in step 1
41
83
 
42
- Common actions (undo, redo, flatten actions to initial state) are provided by this gem.
43
- Combined with turbo frames for rendering partial page updates this makes it easy to
44
- create a very smooth user experience.
84
+ ### Benefits
85
+
86
+ - Straightforward workflow
87
+ - Common actions (undo, redo, flatten actions to initial state) are provided by this gem.
88
+ Combined with turbo frames for rendering partial page updates this makes it easy to
89
+ create a very smooth user experience
90
+ - You can create a store of attributes within a single ActiveRecord model.
91
+ In a Single Page App (SPA) lots of settings may be needed for a good user
92
+ experience. It may be a lot of work to store these in multiple models.
93
+ A redux store can hold an arbitrary amount of attributes
45
94
 
46
95
  ## Usage
47
96
  ### Model
@@ -112,7 +161,7 @@ Methods `flatten?` and `flatten!` can be used in a view and controller:
112
161
  ```
113
162
 
114
163
  ### Sequence ID
115
- As a convenience a sequence ID id available which should always return a unique id
164
+ As a convenience a sequence ID id is available which should always return a unique id
116
165
  (within the context of the model instance). To get the next sequence id use `next_seq_id`,
117
166
  to get the current sequence value use `seq_id`.
118
167
  You could use a sequence in a reducer function to make sure every added item is assigned a unique id.
@@ -175,7 +224,7 @@ cd rails_redhot
175
224
  bundle install
176
225
  cd test/dummy
177
226
  rails db:setup
178
- rails server
227
+ bin/dev
179
228
  ```
180
229
 
181
230
  Then open the [application](http://localhost:3000/foobars).
@@ -63,7 +63,7 @@ module RailsRedhot
63
63
  end
64
64
 
65
65
  define_method('flatten!') do
66
- self.initial_state = state
66
+ self.initial_state = view_state
67
67
  self.state = nil
68
68
  self.head = -1
69
69
  self.actions = []
@@ -1,4 +1,4 @@
1
1
  module RailsRedhot
2
2
  # Gem version
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_redhot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivo Herweijer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-30 00:00:00.000000000 Z
11
+ date: 2022-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.2.32
64
+ rubygems_version: 3.3.7
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: REDux pattern for HOTwire == Redhot