Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/docs known issues #117

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 2 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,5 @@ An interface defining the configuration attributes to bootstrap `localStorageSyn
* `syncCondition` (optional) `(state) => boolean`: When set, sync to storage medium will only occur when this function returns a true boolean. Example: `(state) => state.config.syncToStorage` will check the state tree under config.syncToStorage and if true, it will sync to the storage. If undefined or false it will not sync to storage. Often useful for "remember me" options in login.
Usage: `localStorageSync({keys: ['todos', 'visibilityFilter'], storageKeySerializer: (key) => 'cool_' + key, ... })`. In this example `Storage` will use keys `cool_todos` and `cool_visibilityFilter` keys to store `todos` and `visibilityFilter` slices of state). The key itself is used by default - `(key) => key`.

---
### ~~`localStorageSyncAndClean(keys: any[], rehydrate: boolean = false, removeOnUndefined: boolean = false): Reducer`~~
**This function is deprecated and soon will be removed, please use _localStorageSync(LocalStorageConfig)_.**

A shorthand that wraps the functionalities of `localStorageSync` and asumes `localStorage` as the storage.

#### Arguments

* `keys` State keys to sync with local storage. The keys can be defined in two different formats:
* \(*string[]*): Array of strings representing the state (reducer) keys. Full state will be synced (e.g. `localStorageSync(['todos'])`).

* \(*object[]*): Array of objects where for each object the key represents the state key and the value represents custom serialize/deserialize options. This can be one of the following:

* An array of properties which should be synced. This allows for the partial state sync (e.g. `localStorageSync([{todos: ['name', 'status'] }, ... ])`).

* A reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).

* An object with properties that specify one or more of the following:

* serialize: A function that takes a state object and returns a plain json object to pass to json.stringify.

* deserialize: A function that takes that takes the raw JSON from JSON.parse and builds a state object.

* replacer: A replacer function as specified in the [JSON.stringify documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).

* space: The space value to pass JSON.stringify.

* reviver: A reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).

* filter: An array of properties which should be synced (same format as the stand-along array specified above).
* `rehydrateState` \(*boolean? = false*): Pull initial state from local storage on startup.
* `removeOnUndefined` \(*boolean? = false*): Specify if the state is removed from the storage when the new value is undefined.
## Known issues
* Currently, rehydration restores the objects entirely without checking if the restored keys are still desired by the config, and without removing unwanted ones. This is a regression bug that we chose to accept when solving a more serious bug.
22 changes: 0 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,28 +271,6 @@ export const localStorageSync = (config: LocalStorageConfig) => (
};
};

/*
@deprecated: Use localStorageSync(LocalStorageConfig)

Wraps localStorageSync functionality acepting the removeOnUndefined boolean parameter in order
to clean/remove the state from the browser on situations like state reset or logout.
Defines localStorage as default storage.
*/
export const localStorageSyncAndClean = (
keys: any[],
rehydrate: boolean = false,
removeOnUndefined: boolean = false
) => (reducer: any) => {
let config: LocalStorageConfig = {
keys: keys,
rehydrate: rehydrate,
storage: localStorage,
removeOnUndefined: removeOnUndefined
};

return this.localStorageSync(config);
};

export interface LocalStorageConfig {
keys: any[];
rehydrate?: boolean;
Expand Down