@reduxjs/toolkit#Action TypeScript Examples

The following examples show how to use @reduxjs/toolkit#Action. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Tools.ts    From foundation-lib-spa-core with Apache License 2.0 6 votes vote down vote up
export function observeStore<T = any, S = any, A extends Action<any> = AnyAction, M extends Middlewares<S> = Middlewares<S>>
(   
    store: EnhancedStore<S, A, M>, 
    select: (state: S) => T, 
    onChange: (state: T) => void
) : Unsubscribe
{
    let currentState : any;

    function handleChange() {
        const nextState = select(store.getState());
        if (nextState !== currentState) {
            currentState = nextState;
            onChange(currentState);
        }
    }

    const unsubscribe = store.subscribe(handleChange);
    handleChange();
    return unsubscribe;
}
Example #2
Source File: store.ts    From prompts-ai with MIT License 6 votes vote down vote up
reducers = combineReducers(
    {
      editor: undoable(editorReducer, {
          limit: 10,
          filter: (action: Action) => {
              return filteredActions.includes(action.type);
          },
          groupBy: (action) => filteredActions.includes(action.type) ? `${action.type}_${Math.floor(Date.now() / 1000 / 10)}` : null,
      })
    }
)
Example #3
Source File: location.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
locationReducer = (state: LocationState = initialState, action: Action<unknown>) => {
  if (updateLocation.match(action)) {
    const payload: LocationUpdate = action.payload;
    const { path, routeParams, replace } = payload;
    let query = payload.query || state.query;

    if (payload.partial) {
      query = _.defaults(query, state.query);
      query = _.omitBy(query, _.isNull);
    }

    return {
      url: renderUrl(path || state.path, query),
      path: path || state.path,
      query: { ...query },
      routeParams: routeParams || state.routeParams,
      replace: replace === true,
      lastUpdated: new Date().getTime(),
    };
  }

  return state;
}
Example #4
Source File: store.ts    From ts-redux-react-realworld-example-app with MIT License 5 votes vote down vote up
export function dispatchOnCall(action: Action) {
  return () => store.dispatch(action);
}
Example #5
Source File: Spa.ts    From foundation-lib-spa-core with Apache License 2.0 5 votes vote down vote up
private _initRedux() : void
    {
        const reducers: { [key : string ]: Reducer<any, Action> } = {};
        this._modules.forEach(x => { const ri = x.GetStateReducer(); if (ri) { reducers[ri.stateKey] = ri.reducer }});
        this._state = configureStore({ reducer: reducers });
        this._state.dispatch({ type: '@@EPI/INIT' });
    }
Example #6
Source File: Tools.ts    From foundation-lib-spa-core with Apache License 2.0 5 votes vote down vote up
export function setLanguage<S = any, A extends Action<any> = AnyAction, M extends Middlewares<S> = Middlewares<S>>(newLanguage: string, store: EnhancedStore<S,A,M>) : void
{
    const action : A = {
        type: 'OptiContentCloud/SetState',
        currentLanguage: newLanguage
    } as unknown as A;
    store.dispatch(action);
}
Example #7
Source File: Tools.d.ts    From foundation-lib-spa-core with Apache License 2.0 5 votes vote down vote up
export declare function observeStore<T = any, S = any, A extends Action<any> = AnyAction, M extends Middlewares<S> = Middlewares<S>>(store: EnhancedStore<S, A, M>, select: (state: S) => T, onChange: (state: T) => void): Unsubscribe;
Example #8
Source File: Tools.d.ts    From foundation-lib-spa-core with Apache License 2.0 5 votes vote down vote up
export declare function setLanguage<S = any, A extends Action<any> = AnyAction, M extends Middlewares<S> = Middlewares<S>>(newLanguage: string, store: EnhancedStore<S, A, M>): void;
Example #9
Source File: reducers.ts    From xcloud-keyboard-mouse with GNU General Public License v3.0 5 votes vote down vote up
function isWriteAction(action: { type: string }): action is Action {
  return (
    action.type.startsWith(deleteGamepadConfigAction.typePrefix) ||
    action.type.startsWith(modifyGamepadConfigAction.typePrefix)
  );
}