1.1.1 • Published 11 months ago

@jswork/rtk-config-store v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

rtk-config-store

Redux toolkit config store with next.

version license size download

installation

npm install @jswork/rtk-config-store

usage

store.ts

import { scanWebpack } from '@jswork/scan-modules';
import RtkConfigStore from '@jswork/rtk-config-store';

// when webpack const context = require.context('./modules', true, /.ts$/); const modules = scanWebpack(context, { modules: '/modules/' }); export const store = RtkConfigStore({ modules, preloadedState: {}, reducer: {} });

// Infer the RootState and AppDispatch types from the store itself export type RootState = ReturnType; // Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState} export type AppDispatch = typeof store.dispatch;

> app.ts
```ts
import { Provider } from 'react-redux';
import { store } from '@/shared/stores/root';

interface IReduxProviderProps extends React.PropsWithChildren {}

export default function (props: IReduxProviderProps) {
  const { children } = props;
  return <Provider store={store}>{children}</Provider>;
}

define a slice use nx.$createSlice

export default nx.$createSlice({
  name: 'user',
  initialState: {
    token: null,
    profile: JSON.parse(localStorage.getItem('profile'))
  },
  reducers: {
    setToken: (state, action) => {
      state.token = action.payload;
    },
    setProfile: (state, action) => {
      state.profile = action.payload;
    }
  },
  watch: {
    profile: (newValue, oldValue, objectPath) => {
      console.log('profile:', newVal, oldVal, objectPath);
    }
  }
});

types

/// <reference types="@jswork/rtk-config-store/global.d.ts" />

license

Code released under the MIT license.

1.1.1

11 months ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.27

1 year ago

1.0.16

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.22

1 year ago

1.0.11

1 year ago

1.0.21

1 year ago

1.0.10

1 year ago

1.0.20

1 year ago

1.0.26

1 year ago

1.0.15

1 year ago

1.0.25

1 year ago

1.0.14

1 year ago

1.0.24

1 year ago

1.0.13

1 year ago

1.0.23

1 year ago

1.0.12

1 year ago

1.0.4

1 year ago