1.7 KiB
1.7 KiB
Smartstate Implementation Notes
Current API (as of analysis)
State Part Initialization
- State parts can be created with different init modes: 'soft', 'mandatory', 'force', 'persistent'
- Persistent mode automatically calls init() internally - no need to call it manually
- WebStore integration for persistent state uses IndexedDB
Actions
- Actions are created with
createAction()
method - Two ways to dispatch actions:
stateAction.trigger(payload)
- returns Promiseawait statePart.dispatchAction(stateAction, payload)
- returns Promise
- Both methods now return the same Promise, providing flexibility in usage
State Management Methods
select()
- returns Observable with startWith current statewaitUntilPresent()
- waits for specific state conditionstateSetup()
- async state initialization with cumulative defernotifyChangeCumulative()
- defers notification to end of call stack (no callback parameter)
State Hash Detection
- Uses SHA256 hash to detect actual state changes
- Bug: Currently stores the state object itself as hash instead of the actual hash
- This prevents proper duplicate notification prevention
Type System
- Can use either enums or string literal types for state part names
- Test uses simple string types:
type TMyStateParts = 'testStatePart'
Fixed Issues in Documentation
- Updated trigger() to return Promise (API enhancement)
- Added dispatchAction as alternative method
- Corrected notifyChangeCumulative usage
- Clarified persistent mode auto-init
- Added stateSetup documentation
- Fixed state hash detection description
- Both trigger() and dispatchAction() now return Promise for consistency