How to use the redux-starter-kit.createSlice function in redux-starter-kit

To help you get started, we’ve selected a few redux-starter-kit examples, based on popular ways it is used in public projects.

github SafetyCulture / grpc-web-devtools / src / state / toolbar.js View on Github external
// Copyright (c) 2019 SafetyCulture Pty Ltd. All Rights Reserved.

import { createSlice } from "redux-starter-kit";

const toolbarSlice = createSlice({
  slice: 'toolbar',
  initialState: {
    filterIsOpen: true,
    filterIsEnabled: false,
    filterValue: "",
  },
  reducers: {
    toggleFilter(state) {
      state.filterIsOpen = !state.filterIsOpen;
    },
    setFilterValue(state, action) {
      const { payload } = action;
      state.filterValue = payload;
      state.filterIsEnabled = !!(state.filterValue && state.filterValue.length > 0);
    }
  },
github rishabh3112 / webpack-ui / src / client / src / store / features / webpack.js View on Github external
import { createSlice } from 'redux-starter-kit';

// To handle webpack state
const webpack = createSlice({
    slice: "webpack",
    initialState: "",
    reducers: {
        update: (state, action) => action.payload,
    }
});

export const { actions, reducer } = webpack;

const { update } = actions;

export const refresh = () => async (dispatch) => {
    const webpack = await request('/api/init', {type: "refresh"});
    dispatch(update(webpack.webpack));
}
github snphq / react-starter-boilerplate / src / models / users / slice.js View on Github external
/* eslint-disable no-param-reassign */

import { createSlice } from 'redux-starter-kit';

const usersSlice = createSlice({
  name: 'users',
  initialState: {
    list: [],
    fetching: false,
  },
  reducers: {
    fetchUser: state => {
      state.fetching = true;
      state.list = [];
    },
    fetchUsers: state => {
      state.fetching = true;
      state.list = [];
    },
    fetchUserSuccess(state, { payload }) {
      state.fetching = false;
github SafetyCulture / grpc-web-devtools / src / state / network.js View on Github external
import { createSlice } from "redux-starter-kit";
import Fuse from 'fuse.js';
import { setFilterValue } from "./toolbar";

var options = {
  shouldSort: false,
  threshold: 0.1,
  distance: 10000,
  keys: [
    'method',
  ]
};
var fuse = new Fuse(null, options);

const networkSlice = createSlice({
  slice: 'network',
  initialState: {
    preserveLog: false,
    selectedIdx: null,
    selectedEntry: null,
    log: [
    ],
    _filterValue: '',
    _logBak: [],
  },
  reducers: {
    networkLog(state, action) {
      const { log, _filterValue, _logBak } = state;
      const { payload, } = action;
      if (payload.method) {
        const parts = payload.method.split('/')
github markerikson / rsk-github-issues-experiment / src / features / RepoSearch / repoDetails.ts View on Github external
import { createSlice, PayloadAction, Action } from "redux-starter-kit";
import { ThunkAction } from "redux-thunk";

import { getRepoDetails, RepoDetails } from "api/githubAPI";
import { RootState } from "store";

interface RepoDetailsState {
    openIssuesCount: number;
    error: Error | null;
}

const repoDetails = createSlice({
    slice: "repoDetails",
    initialState: {
        openIssuesCount: -1,
        error: null,
    } as RepoDetailsState,
    reducers: {
        getRepoDetailsSuccess(state, action: PayloadAction<RepoDetails>) {
            state.openIssuesCount = action.payload.open_issues_count;
            state.error = null;
        },
        getRepoDetailsFailed(state, action: PayloadAction<Error>) {
            state.openIssuesCount = -1;
            state.error = action.payload;
        },
    },
});
github markerikson / rsk-github-issues-experiment / src / features / IssuesDisplay / issuesDisplay.ts View on Github external
type CurrentDisplayState = {
    page: number;
} & CurrentDisplay &
    CurrentRepo;

let initialState: CurrentDisplayState = {
    org: "rails",
    repo: "rails",
    page: 1,
    displayType: "issues",
    issueId: 0,
};

type IST = (typeof initialState)["displayType"];

const issuesDisplay = createSlice({
    slice: "issuesDisplay",
    initialState,
    reducers: {
        displayRepo(state, action: PayloadAction<CurrentRepo>) {
            const { org, repo } = action.payload;
            state.org = org;
            state.repo = repo;
        },
        setCurrentPage(state, action: PayloadAction<number>) {
            state.page = action.payload;
        },
        setCurrentDisplayType(state, action: PayloadAction<CurrentDisplayPayload>) {
            const { displayType, issueId } = action.payload;
            state.displayType = displayType;
            if (issueId !== undefined) {
                state.issueId = issueId;
github difysjs / difys / src / Modules / Store / reducers / slices.js View on Github external
import { createSlice } from "redux-starter-kit";
import * as actions from "../actions";

const metadata = createSlice({
	slice: "metadata",
	initialState: {},
	reducers: actions.metadataActions
});

const accounts = createSlice({
	slice: "accounts",
	initialState: {},
	reducers: actions.accountActions
});

export { metadata, accounts };
github difysjs / difys / src / Modules / Store / reducers / slices.js View on Github external
import { createSlice } from "redux-starter-kit";
import * as actions from "../actions";

const metadata = createSlice({
	slice: "metadata",
	initialState: {},
	reducers: actions.metadataActions
});

const accounts = createSlice({
	slice: "accounts",
	initialState: {},
	reducers: actions.accountActions
});

export { metadata, accounts };
github iran-react-community / elegant-react-native / app / store / reducers / user.js View on Github external
import {createSlice} from 'redux-starter-kit';

const userSlice = createSlice({
  slice: 'users',
  initialState: {loggedIn: false, onCheck: false},
  reducers: {
    login: state => ({...state, onCheck: true}),
    loginSuccess(state) {
      state.onCheck = false;
      state.loggedIn = true;
    },
    logout: state => ({...state, onCheck: true}),
    logoutSuccess(state) {
      state.onCheck = false;
      state.loggedIn = false;
    },
  },
});
github magarcia / todomvc-redux-starter-kit / src / ducks / todos.js View on Github external
state.map(todo =>
    todo.id === action.payload.id
      ? { ...todo, completed: !todo.completed }
      : todo
  );
const completeAllTodos = state => {
  const areAllMarked = state.every(todo => todo.completed);
  return state.map(todo => ({
    ...todo,
    completed: !areAllMarked
  }));
};

const clearCompleted = state => state.filter(todo => todo.completed === false);

const todos = createSlice({
  slice: "todos",
  initialState: [],
  reducers: {
    add: addTodo,
    delete: deleteTodo,
    edit: editTodo,
    complete: completeTodo,
    completeAll: completeAllTodos,
    clearCompleted: clearCompleted
  }
});

todos.selectors.getVisibleTodos = createSelector(
  [getVisibilityFilter, todos.selectors.getTodos],
  (visibilityFilter, todos) => {
    switch (visibilityFilter) {

redux-starter-kit

A simple set of tools to make using Redux easier

MIT
Latest version published 3 years ago

Package Health Score

72 / 100
Full package analysis