@trigger is used to trigger when effect or state dispatch fires
@trigger(action, options?)
// The action name will be `{sink}/{effect|state}`typeaction=stringinterfaceoptions {// trigger excution order, default 0 priority?:number;// lazy loaded trigger will excute after action, default true lazyLoad?:boolean;// pass raw action object to trigger function, default false rawAction?:boolean;// formatter use to arguments before it hits trigger functionformatter?:Function;}
import { sink, state, effect } from'redux-sink';@sink('weather')exportclassWeatherSink { @state humidity =0; @state weather = { temperature:0, humidity:0 };// when weather action dispatches, set humidity as same as weather @trigger('weather/weather', { formatter: (weather) =>weather.humidity })functionweatherTrigger(humidity ) {this.humidity = humidity; }}
the trigger is a powerful tool for make redux as an event sourcing system, but may cause infinity loop to redux actions when setting bad triggers, be careful when using it