import React from 'react' ; import { useBindStore , StoreActions , createStore , useStoreSlice } from '../../dist/' ; import { devtools } from '../../dist/middlewares' ; import SliceView from './SliceView' ; export type State = { value1 : string ; value2 : string ; } ; export type Actions = { setValue1 : ( text : string ) => void ; setValue2 : ( text : string ) => void ; } ; export type ConflictPolicyViewProps = State & Actions ; export const getInitialState = ( ) : State => ( { value1 : '' , value2 : '' , } ) ; function getTimeoutPromise < C > ( timeout , result = null ) { return new Promise ( ( res ) => { setTimeout ( res , timeout , result ) ; } ) ; } const actionsImpl = { setValue1 : { getPromise : ( { args : [ v ] } ) => getTimeoutPromise ( 500 , v ) , effects : ( { s , res } ) => ( { ... s , value1 : res } ) , } , setValue2 : { getPromise : ( { args : [ v ] } ) => getTimeoutPromise ( 1000 , v ) , effects : ( { s , res } ) => ( { ... s , value2 : res } ) , } , } ; export const store = createStore ( getInitialState , actionsImpl , { name : 'Slice store' } , [ devtools ( ) ] ) ; function Slice ( ) { useBindStore ( store ) ; return < SliceView />; } export default Slice ;