0.0.13 • Published 5 years ago

@36node/redux-cron v0.0.13

Weekly downloads
14
License
MIT
Repository
github
Last release
5 years ago

Redux Cron

An redux library for doing cron job

version downloads

Use

Config redux

import { cronReducer } from "@36node/redux-cron";

export default combineReducers({
  crons: cronReducer,
});

Actions

import { createCronActions } from "@36node/redux-cron";
import { put } from "redux-saga/effects";

const cronActions = createCronActions("SOME_KEY", {
  // onTick can be a fucntion or an action object
  onTick: function*(count, actions) {
    // count: current tick count
    // actions: cron actions

    if (count >= 10) {
      yield put(actions.stop());
    }
  },
});

// dispatch, interval 1s
dispatch(cronActions.start(1000));
export interface CronActions {
  start: (interval?: number, meta?: Object) => StartAction; // start cron
  stop: (meta?: Object) => StopAction; // stop cron
  cancel: (meta?: Object) => CancelAction; // reset cron, set count=0
}

Redux state

export interface CronState {
  count: number; // tick count
  lastAt: string; // last tick at
  lastStartAt: string; // last start at
  lastStopAt: string; // last stop at
  interval: number; // current interval
  status: "STOP" | "RUNNING"; // current status
}

Selectors

import { createCronSelector } from "@36node/redux-cron";

// define
const selector = createCronSelector("SOME_KEY");

// use
const cronState = selector(state);
0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago