Last active
December 12, 2017 20:19
-
-
Save notoriousb1t/6f4254db618b20a9a9470957050821ad to your computer and use it in GitHub Desktop.
Proposal for a state machine with devtools tooling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const machine = LIBRARY.StateMachine({ | |
| /* ... json data ... */ | |
| }) | |
| // move to the state | |
| machine.transition('initial') | |
| // move to both states simultaneously | |
| machine.transition(['initial', 'secondary']) | |
| // go to state with immediate flag and stack initial with the existing state | |
| machine.transition('initial', { immediate: true, additive: true }) | |
| // a render function provided by the animation library | |
| machine.onUpdate(ANIMATION_LIB.renderState) | |
| // replace configuration | |
| machine.loadJSON(/* ... json data ... */) | |
| // remove all update handlers | |
| machine.dispose() | |
| // --- | |
| // Interfaces | |
| // --- | |
| interface IStateRenderer { | |
| (machine: IStateMachine, current: IState, next: IState): any | |
| } | |
| interface IState { | |
| name: string | |
| target: any | |
| data: { | |
| // registered type or built-in type | |
| type: string | |
| immediate: boolean | |
| } | |
| props: { | |
| // whatever properties or settings are needed for the state | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const machine = LIBRARY.StateMachine({ ... }) | |
| // loaded via separate package | |
| LIBRARY.devtools.tinker(machine) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| LIBRARY.devtools.registerSchema([ | |
| { | |
| type: 'Tween', | |
| allowAny: true, | |
| properties: { | |
| target: 'string', | |
| easing: 'cubic-bezier' | |
| } | |
| } | |
| ]) | |
| // --- | |
| // Interfaces | |
| // --- | |
| interface ISchema { | |
| name: string | |
| props: Record<string, ISchemaProperty | string> | |
| } | |
| interface ISchemaProperty { | |
| name: string | |
| type?: string | |
| subtype?: string | |
| defaultValue?: any | |
| allowAny?: boolean | |
| properties?: Record<string, ISchemaProperty | string> | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment