Skip to content

Commit

Permalink
feat: add combine storage class
Browse files Browse the repository at this point in the history
Add possibility to configure storage and attributes for each store
  • Loading branch information
MatthewPattell committed May 28, 2024
1 parent 8142954 commit d67fd8d
Show file tree
Hide file tree
Showing 35 changed files with 2,583 additions and 12,175 deletions.
41 changes: 0 additions & 41 deletions .eslintrc.cjs

This file was deleted.

5 changes: 1 addition & 4 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ jobs:
run: echo "${{ github.event.pull_request.title }}" | npx --no-install commitlint -g commitlint.config.js

- name: Build lib
run: npm run build:dev

- name: Install example dependencies
run: cd example && npm ci
run: npm run build

- name: Typescript check
run: npm run ts:check
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ npm i --save @lomray/react-mobx-manager @lomray/consistent-suspense

__NOTE:__ this package use [@lomray/consistent-suspense](https://github.com/Lomray-Software/consistent-suspense) for generate stable id's inside Suspense.

__Choose one of store id generating strategy__:
__Choose one of store id generating strategy (1 or 2 or 3)__:

1. Configure your bundler to keep classnames and function names. Store id will be generated from class names (chose unique class names).
- **React:** (craco or webpack config, terser options)
Expand Down Expand Up @@ -276,6 +276,7 @@ const storeManager = new Manager({
*/
storage: new MobxLocalStorage(), // React
// storage: new MobxAsyncStorage(AsyncStorage), // React Native
// storage: new CombinedStorage({ local: MobxAsyncStorage, cookie: CookieStorage }), // Define multiple storages
/**
* Optional: provide some params for access from store constructor
* E.g. we can provide our api client for access from the store
Expand Down Expand Up @@ -382,6 +383,16 @@ const manager = Manager.get();
* Enable persisting state for store
*/
const storeClass = Manager.persistStore(class MyStore {}, 'my-store');

/**
* Choose storage and attributes
*/
const storeClass2 = Manager.persistStore(class MyStore {}, 'my-store', {
attributes: {
local: ['someProp'], // thees attributes will be stored in local storage
cookie: ['specificProp'], // thees attributes will be stored in cookie storage
}
});
```

### withStores
Expand Down
35 changes: 35 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import lomrayConfig from '@lomray/eslint-config-react';
// noinspection NpmUsedModulesInstalled
import baseConfig from '@lomray/eslint-config';
// noinspection NpmUsedModulesInstalled
import globals from 'globals';

const customFilesIgnores = {
...baseConfig['filesIgnores'],
files: [
...baseConfig['filesIgnores'].files,
'__tests__/**/*.{ts,tsx,*.ts,*tsx}',
'__mocks__/**/*.{ts,tsx,*.ts,*tsx}',
'__helpers__/**/*.{ts,tsx,*.ts,*tsx}',
],
}

export default [
...lomrayConfig.config(customFilesIgnores),
{
...customFilesIgnores,
languageOptions: {
globals: {
...globals.node,
NodeJS: true,
}
},
rules: {
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-call': 0,
'@typescript-eslint/no-unsafe-return': 0,
}
},
];
40 changes: 0 additions & 40 deletions example/.eslintrc.cjs

This file was deleted.

23 changes: 0 additions & 23 deletions example/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions example/README.md

This file was deleted.

20 changes: 0 additions & 20 deletions example/index.html

This file was deleted.

Loading

0 comments on commit d67fd8d

Please sign in to comment.