File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed
Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,11 @@ class BaseState {
5656 * states are always well defined, it guarantees that UI updates are made at transition completion (final state) only.
5757 */
5858export class StateTransition extends BaseState {
59+ constructor ( NAME , func ) {
60+ super ( NAME ) ;
61+ if ( typeof func === "function" )
62+ this . usrDefined_transition = func ;
63+ }
5964 /**
6065 * User defined transition to be overwritten.
6166 * @param input Any meaningfull data.
Original file line number Diff line number Diff line change @@ -60,12 +60,19 @@ class BaseState{
6060
6161}
6262
63+
64+ type usrCallback = ( input ?: any ) => void ;
65+
6366/**
6467 * A stateTransition is a global function that is meant to apply simultaneously an overall state change,
6568 * this can be made of just one variable change or multiple stateVariables changes at the same time, so that the initial and final
6669 * states are always well defined, it guarantees that UI updates are made at transition completion (final state) only.
6770 */
6871export class StateTransition extends BaseState {
72+ constructor ( NAME :string , func ?:usrCallback ) {
73+ super ( NAME ) ;
74+ if ( typeof func === "function" ) this . usrDefined_transition = func ;
75+ }
6976 /**
7077 * User defined transition to be overwritten.
7178 * @param input Any meaningfull data.
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ export default function (){
66
77 let counter_st = 0 ;
88 let counter_gb = 0 ;
9+ let counter_st_init = 0 ;
910
1011 describe ( 'Transition' , ( ) => {
1112
@@ -14,6 +15,11 @@ export default function (){
1415 let mess = new Message ( "pollo" ) ;
1516 let message = "ciao" ;
1617
18+ let st_init = new StateTransition ( "test" , ( i ) => {
19+ if ( i ) counter_st_init = i ;
20+ else counter_st_init ++ ;
21+ } ) ;
22+
1723
1824 let test_target = document . createElement ( "h1" ) ;
1925 let test_target2 = document . createElement ( "h2" ) ;
@@ -103,6 +109,11 @@ export default function (){
103109 chai . assert . Throw ( func , "Forbidden multiple-update during an update callback loop" ) ;
104110 chai . assert . Throw ( func2 , "Target is undefined" ) ;
105111
112+ st_init . applyTransition ( ) ;
113+ chai . assert . equal ( counter_st_init , 1 , "standalone init ok" ) ;
114+ st_init . applyTransition ( 7 ) ;
115+ chai . assert . equal ( counter_st_init , 7 , "standalone init ok 2" ) ;
116+
106117 } ) ;
107118 it ( 'Detaches' , ( ) => {
108119
You can’t perform that action at this time.
0 commit comments