Commit a5aeeaa
Projections redesigned
Projection class is redesigned here. It now only suports read & reduce
based on existing events, without possibility to subscribe for events.
New & redesigned:
* replace `from_all_streams` & `from_stream` with passing read scopes
to `call` method, it allows to fully use all read specification
features to define what events should be handled
* instead of providing several streams (and starting points) to be
processed `call` expects several read scopes
* `when` method replaced with `on` method, with usage consistent with
`on` handlers (as in `AggregateRoot`), the `on` methods require block
to process state & event and it must return new projection state
* allows to use simple values as initial state, no need to use hash to
pass values, `nil` is the initial default state now
* initial state is passed to projection using costructor
Typical usage:
```ruby
account_balance =
RailsEventStore::Projection
.new(0.0)
.on(MoneyDeposited) { |state, event| state += event.data[:amount] }
.on(MoneyWithdrawn) { |state, event| state -= event.data[:amount] }
.call(client.read)
```1 parent 7368e94 commit a5aeeaa
File tree
2 files changed
+97
-207
lines changed- ruby_event_store
- lib/ruby_event_store
- spec
2 files changed
+97
-207
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 7 | + | |
19 | 8 | | |
20 | | - | |
| 9 | + | |
21 | 10 | | |
22 | 11 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 12 | + | |
| 13 | + | |
29 | 14 | | |
30 | | - | |
31 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
32 | 18 | | |
| 19 | + | |
| 20 | + | |
33 | 21 | | |
34 | 22 | | |
35 | 23 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 24 | + | |
53 | 25 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | 26 | | |
59 | | - | |
60 | | - | |
61 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
62 | 30 | | |
63 | 31 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 32 | + | |
77 | 33 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 34 | + | |
| 35 | + | |
84 | 36 | | |
85 | 37 | | |
86 | | - | |
87 | | - | |
| 38 | + | |
| 39 | + | |
88 | 40 | | |
89 | 41 | | |
90 | 42 | | |
91 | | - | |
92 | | - | |
| 43 | + | |
93 | 44 | | |
94 | 45 | | |
95 | 46 | | |
0 commit comments