@@ -23,7 +23,8 @@ Here's a snapshot of some notable highlights:
23
23
✅   ; Immutability on demand
24
24
✅   ; Rich plugin ecosystem
25
25
✅   ; Native IndexedDB support
26
- ✅   ; Granular Undo/Redo
26
+ ✅   ; Transactional Undo/Redo
27
+ ✅   ; Global State Snaphots and Rollbacks
27
28
✅   ; Devtools support
28
29
✅   ; Effect and Store status tracking
29
30
✅   ; Realtime store performance statistics
@@ -46,7 +47,7 @@ Here's a snapshot of some notable highlights:
46
47
- 📦 Don't want to use a class for stores? - You don't have to.
47
48
- 🛠️ Tired of debugging state changes in the console? - Enable redux devtools.
48
49
- 🪄 Still want some good old logging magic? - Enable Store logger plugin
49
- - ⏳ Need to keep track of store history and perform undo/redo operations? - Enable the history plugin .
50
+ - ⏳ Need to keep track of store history and perform undo/redo operations? - track the history.
50
51
- 💾 Want to sync your state with local storage? - Enable the persistence plugin.
51
52
- 🗄️ Need a more sophisticated store storage or building an offline app? - Use IndexedDB adapter
52
53
- 📈 Need to get notified of whether your store is modified or currently loading? - Enable the Store Status plugin.
@@ -67,7 +68,8 @@ npm install signalstory
67
68
``` typescript
68
69
import { produce } from ' immer' ;
69
70
70
- // Fully immutable store class with immer.js for boosting immutable mutation performance
71
+ // Immutable store class using immer.js for boosting immutable mutations
72
+ @Injectable ({ providedIn: ' root' })
71
73
class BookStore extends ImmutableStore <Book []> {
72
74
constructor () {
73
75
super ({
@@ -76,11 +78,13 @@ class BookStore extends ImmutableStore<Book[]> {
76
78
mutationProducerFn: produce ,
77
79
plugins: [
78
80
useDevtools (),
79
- useStoreHistory (),
80
- useStorePersistence (),
81
+ usePerformanceCounter (),
81
82
useLogger (),
82
83
useStoreStatus (),
83
- usePerformanceCounter (),
84
+ useStorePersistence (
85
+ configureIndexedDb ({
86
+ dbName: ' SharedDatabase' ,
87
+ })),
84
88
],
85
89
});
86
90
@@ -105,24 +109,34 @@ class BookStore extends ImmutableStore<Book[]> {
105
109
}, ' Add Book To Collection' );
106
110
}
107
111
}
112
+ ```
108
113
109
-
114
+ ``` typescript
110
115
// Encapsulated multi store query object
111
116
export const BooksAndPublishersByAuthorInSwitzerlandQuery = createQuery (
112
117
[BookStore , PublisherStore ],
113
118
(books , publishers , authorId : string ) => {
114
119
const booksFromAuthor = books .state ().filter (x => x .author === authorId );
115
- const publishersInSwitzerland = publishers .state ().filter (x => x .country === ' CH' );
120
+ const publishersInSwitzerland = publishers
121
+ .state ()
122
+ .filter (x => x .country === ' CH' );
116
123
117
124
return booksFromAuthor .map (book => ({
118
125
book ,
119
- publisher: publishersInSwitzerland .find (p => p .id === book .mainPublisherId ),
126
+ publisher: publishersInSwitzerland .find (
127
+ p => p .id === book .mainPublisherId
128
+ ),
120
129
}));
121
130
}
122
131
);
123
132
// And then run it
124
- const query = myBookStore .runQuery (BooksAndPublishersByAuthorInSwitzerlandQuery , ' sapowski' );
133
+ const query = myBookStore .runQuery (
134
+ BooksAndPublishersByAuthorInSwitzerlandQuery ,
135
+ ' sapowski'
136
+ );
137
+ ```
125
138
139
+ ``` typescript
126
140
// Encapsulated effect object
127
141
export const fetchBooksEffect = createEffect (
128
142
' Fetch Books' ,
@@ -150,6 +164,26 @@ const initializedSignal = initialized(myBookStore); // true after initializing e
150
164
const modifiedSignal = modified (myBookStore ); // true after store update
151
165
```
152
166
167
+ ``` typescript
168
+ // Track history spanning multiple stores
169
+ const tracker = trackHistory (50 , store1 , store2 );
170
+
171
+ // Undo single commands
172
+ store1 .set ({ value: 10 }, ' ChangeCommand' );
173
+ tracker .undo ();
174
+
175
+ tracker .beginTransaction (' Transaction Label' );
176
+ store1 .set ({ value: 42 }, ' ChangeCommand' );
177
+ store2 .set ({ value: 23 }, ' AnotherCommand' );
178
+ tracker .endTransaction ();
179
+
180
+ // Undo both commands on store1 and store2 at once
181
+ tracker .undo ();
182
+
183
+ // Redo the whole transaction
184
+ tracker .redo ();
185
+ ```
186
+
153
187
## Sample Application
154
188
155
189
To set up and run the sample app locally, follow the steps below:
0 commit comments