@push.rocks/smartstate 2.0.21 → 2.0.23

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.
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartstate',
6
- version: '2.0.20',
6
+ version: '2.0.23',
7
7
  description: 'A package for handling and managing state in applications.'
8
8
  };
9
9
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx3QkFBd0I7SUFDOUIsT0FBTyxFQUFFLFFBQVE7SUFDakIsV0FBVyxFQUFFLDREQUE0RDtDQUMxRSxDQUFBIn0=
@@ -9,5 +9,5 @@ export declare class StateAction<TStateType, TActionPayloadType> {
9
9
  statePartRef: StatePart<any, any>;
10
10
  actionDef: IActionDef<TStateType, TActionPayloadType>;
11
11
  constructor(statePartRef: StatePart<any, any>, actionDef: IActionDef<TStateType, TActionPayloadType>);
12
- trigger(payload: TActionPayloadType): void;
12
+ trigger(payload: TActionPayloadType): Promise<TStateType>;
13
13
  }
@@ -9,7 +9,7 @@ export class StateAction {
9
9
  this.actionDef = actionDef;
10
10
  }
11
11
  trigger(payload) {
12
- this.statePartRef.dispatchAction(this, payload);
12
+ return this.statePartRef.dispatchAction(this, payload);
13
13
  }
14
14
  }
15
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdGF0ZS5jbGFzc2VzLnN0YXRlYWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4v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UksQ0FBQyxZQUFZLENBQUMsY0FBYyxDQUFDLElBQUksRUFBRSxPQUFPLENBQUMsQ0FBQztJQUN6RCxDQUFDO0NBQ0YifQ==
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@push.rocks/smartstate",
3
- "version": "2.0.21",
3
+ "version": "2.0.23",
4
4
  "private": false,
5
5
  "description": "A package for handling and managing state in applications.",
6
6
  "main": "dist_ts/index.js",
package/readme.hints.md CHANGED
@@ -1 +1,39 @@
1
-
1
+ # Smartstate Implementation Notes
2
+
3
+ ## Current API (as of analysis)
4
+
5
+ ### State Part Initialization
6
+ - State parts can be created with different init modes: 'soft', 'mandatory', 'force', 'persistent'
7
+ - Persistent mode automatically calls init() internally - no need to call it manually
8
+ - WebStore integration for persistent state uses IndexedDB
9
+
10
+ ### Actions
11
+ - Actions are created with `createAction()` method
12
+ - Two ways to dispatch actions:
13
+ 1. `stateAction.trigger(payload)` - returns Promise<TStatePayload>
14
+ 2. `await statePart.dispatchAction(stateAction, payload)` - returns Promise<TStatePayload>
15
+ - Both methods now return the same Promise, providing flexibility in usage
16
+
17
+ ### State Management Methods
18
+ - `select()` - returns Observable with startWith current state
19
+ - `waitUntilPresent()` - waits for specific state condition
20
+ - `stateSetup()` - async state initialization with cumulative defer
21
+ - `notifyChangeCumulative()` - defers notification to end of call stack (no callback parameter)
22
+
23
+ ### State Hash Detection
24
+ - Uses SHA256 hash to detect actual state changes
25
+ - Bug: Currently stores the state object itself as hash instead of the actual hash
26
+ - This prevents proper duplicate notification prevention
27
+
28
+ ### Type System
29
+ - Can use either enums or string literal types for state part names
30
+ - Test uses simple string types: `type TMyStateParts = 'testStatePart'`
31
+
32
+ ## Fixed Issues in Documentation
33
+ 1. Updated trigger() to return Promise (API enhancement)
34
+ 2. Added dispatchAction as alternative method
35
+ 3. Corrected notifyChangeCumulative usage
36
+ 4. Clarified persistent mode auto-init
37
+ 5. Added stateSetup documentation
38
+ 6. Fixed state hash detection description
39
+ 7. Both trigger() and dispatchAction() now return Promise for consistency
package/readme.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @push.rocks/smartstate
2
- a package that handles state in a good way
2
+ A package for handling and managing state in applications
3
3
 
4
4
  ## Install
5
5
 
@@ -44,13 +44,17 @@ When creating state parts, you can specify different initialization modes:
44
44
 
45
45
  State parts represent separable sections of your state, making it easier to manage and modularize. For example, you may have a state part for user data and another for application settings.
46
46
 
47
- Define an enum for state part names for better management:
47
+ Define state part names using either enums or string literal types:
48
48
 
49
49
  ```typescript
50
+ // Option 1: Using enums
50
51
  enum AppStateParts {
51
- UserState,
52
- SettingsState
52
+ UserState = 'UserState',
53
+ SettingsState = 'SettingsState'
53
54
  }
55
+
56
+ // Option 2: Using string literal types (simpler approach)
57
+ type AppStateParts = 'UserState' | 'SettingsState';
54
58
  ```
55
59
 
56
60
  Now, let's create a state part within our `myAppSmartState` instance:
@@ -67,10 +71,7 @@ const userStatePart = await myAppSmartState.getStatePart<IUserState>(
67
71
  'soft' // Init mode (optional, defaults to 'soft')
68
72
  );
69
73
 
70
- // For persistent state parts, you must call init()
71
- if (mode === 'persistent') {
72
- await userStatePart.init();
73
- }
74
+ // Note: Persistent state parts are automatically initialized internally
74
75
  ```
75
76
 
76
77
  ### Subscribing to State Changes
@@ -107,9 +108,27 @@ const loginUserAction = userStatePart.createAction<ILoginPayload>(async (statePa
107
108
  });
108
109
 
109
110
  // Dispatch the action to update the state
110
- await loginUserAction.trigger({ username: 'johnDoe' });
111
+ loginUserAction.trigger({ username: 'johnDoe' });
112
+ // or await the result
113
+ const newState = await loginUserAction.trigger({ username: 'johnDoe' });
111
114
  ```
112
115
 
116
+ ### Dispatching Actions
117
+
118
+ There are two ways to dispatch actions:
119
+
120
+ ```typescript
121
+ // Method 1: Using trigger on the action (returns promise)
122
+ const newState = await loginUserAction.trigger({ username: 'johnDoe' });
123
+ // or fire and forget
124
+ loginUserAction.trigger({ username: 'johnDoe' });
125
+
126
+ // Method 2: Using dispatchAction on the state part (returns promise)
127
+ const newState = await userStatePart.dispatchAction(loginUserAction, { username: 'johnDoe' });
128
+ ```
129
+
130
+ Both methods return a Promise with the new state, giving you flexibility in how you handle the result.
131
+
113
132
  ### Additional State Methods
114
133
 
115
134
  `StatePart` provides several useful methods for state management:
@@ -118,17 +137,18 @@ await loginUserAction.trigger({ username: 'johnDoe' });
118
137
  // Wait for a specific state condition
119
138
  await userStatePart.waitUntilPresent();
120
139
 
140
+ // Wait for a specific property to be present
141
+ await userStatePart.waitUntilPresent(state => state.username);
142
+
121
143
  // Setup initial state with async operations
122
- await userStatePart.stateSetup(async (state) => {
144
+ await userStatePart.stateSetup(async (statePart) => {
123
145
  // Perform async initialization
124
146
  const userData = await fetchUserData();
125
- return { ...state, ...userData };
147
+ return { ...statePart.getState(), ...userData };
126
148
  });
127
149
 
128
- // Batch multiple state changes for cumulative notification
129
- userStatePart.notifyChangeCumulative(() => {
130
- // Multiple state changes here will result in a single notification
131
- });
150
+ // Defer notification to end of call stack
151
+ userStatePart.notifyChangeCumulative();
132
152
  ```
133
153
 
134
154
  ### Persistent State with WebStore
@@ -142,8 +162,7 @@ const settingsStatePart = await myAppSmartState.getStatePart<ISettingsState>(
142
162
  'persistent' // Mode
143
163
  );
144
164
 
145
- // Initialize the persistent state (required for persistent mode)
146
- await settingsStatePart.init();
165
+ // Note: init() is called automatically for persistent mode
147
166
  ```
148
167
 
149
168
  Persistent state automatically:
@@ -155,7 +174,7 @@ Persistent state automatically:
155
174
 
156
175
  `Smartstate` includes built-in performance optimizations:
157
176
 
158
- - **State Hash Detection**: Uses SHA256 hashing to detect actual state changes, preventing unnecessary notifications when state values haven't truly changed
177
+ - **State Change Detection**: Detects actual state changes to prevent unnecessary notifications when state values haven't truly changed
159
178
  - **Cumulative Notifications**: Batch multiple state changes into a single notification using `notifyChangeCumulative()`
160
179
  - **Selective Subscriptions**: Use selectors to subscribe only to specific state properties
161
180
 
@@ -205,13 +224,13 @@ This repository contains open-source code that is licensed under the MIT License
205
224
 
206
225
  ### Trademarks
207
226
 
208
- This project is owned and maintained by Lossless GmbH. The names and logos associated with Lossless GmbH and any related products or services are trademarks of Lossless GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Lossless GmbH's Trademark Guidelines, and any usage must be approved in writing by Lossless GmbH.
227
+ This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
209
228
 
210
229
  ### Company Information
211
230
 
212
- Lossless GmbH
231
+ Task Venture Capital GmbH
213
232
  Registered at District court Bremen HRB 35230 HB, Germany
214
233
 
215
- For any legal inquiries or if you require further information, please contact us via email at hello@lossless.com.
234
+ For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
216
235
 
217
- By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Lossless GmbH of any derivative works.
236
+ By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartstate',
6
- version: '2.0.20',
6
+ version: '2.0.23',
7
7
  description: 'A package for handling and managing state in applications.'
8
8
  }
@@ -14,7 +14,7 @@ export class StateAction<TStateType, TActionPayloadType> {
14
14
  public actionDef: IActionDef<TStateType, TActionPayloadType>
15
15
  ) {}
16
16
 
17
- public trigger(payload: TActionPayloadType) {
18
- this.statePartRef.dispatchAction(this, payload);
17
+ public trigger(payload: TActionPayloadType): Promise<TStateType> {
18
+ return this.statePartRef.dispatchAction(this, payload);
19
19
  }
20
20
  }