time
time(clock)
Motivation
The method allow to read current time and write it to store
Formulae
- Initialize
$time
withDate.now()
- When
clock
is triggered, callDate.now()
to update$time
with results
Arguments
clock: Event<any> | Effect<any, any, any> | Store<any>
— The unit triggers time reading and updates$time
store
— Time
is a generic type argument used for overriding time reader function. By default, it is number
Returns
$time: Store<Time>
— Store contains unix timestamp snapshot, updates when clock
triggers.
Initialized with Date.now()
Example
time({clock, getNow, initial})
Motivation
The method allow to read current time and write it to store. Object form allows to use additional parameters: getNow
and initial
Formulae
- Initialize
$time
withinitial
, if not present callgetNow
, if not present callDate.now()
- When
clock
is triggered, callgetNow
to update$time
with results, if not present useDate.now()
Arguments
clock: Event<any> | Effect<any, any, any> | Store<any>
— The unit triggers time reading and updates$time
storegetNow: () => Time
— Optional. A custom function to read time whenclock
triggers. Must be synchronous.initial: Time
— Optional. Initial state for$time
store. If not passedgetNow
is called.
— Time
is a generic type argument used for overriding time reader function. By default, it is number
Returns
$time: Store<Time>
— Store contains unix timestamp snapshot, updates when clock
triggers.
If getNow
is overridden, contains value this function returns.
By default, it is number
.
Initialized with initial
, by default, it is Date.now()