-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Data: Add persistence via data plugin interface (#8341)
* Data: Add persistence via data plugin interface * Data: Integrate persistence as first-party plugin * Data: Restore deprecated persistence behaviors * Data: Return default persisted by caught error * Data: Initialize persistence by plugin options * Data: Remove string form variation on use * Data: Refactor persistence as dispatch enhancer * Data: Remove middlewares / enhancers support for store * Data: Remove unused variable * Data: Improve objectStorage spec compliancy Should (a) return null if not set, (b) assign value as string * Data: Fix persistence handling of null value * Data: Fix deprecation key to persist 1. Wrong property accessed used 2. Reducer is already wrapped at point registerStore is called. Detect from plugin instead. * Data: Add tests for WPDataRegistry#use * Data: Remove _ prefix from local variable Not conventional * Data: Update plugins documentation to avoid mention of string usage
- Loading branch information
Showing
19 changed files
with
731 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Data Plugins | ||
============ | ||
|
||
Included here are a set of default plugin integrations for the WordPress data module. | ||
|
||
## Usage | ||
|
||
For any of the plugins included here as directories, call the `use` method to include its behaviors in the registry. | ||
|
||
```js | ||
// npm Usage | ||
import { plugins, use } from '@wordpress/data'; | ||
use( plugins.persistence ); | ||
|
||
// WordPress Globals Usage | ||
wp.data.use( wp.data.plugins.persistence ); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as persistence } from './persistence'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Persistence Plugin | ||
================== | ||
|
||
The persistence plugin enhances a registry to enable registered stores to opt in to persistent storage. | ||
|
||
By default, persistence occurs by [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage). This can be changed using the [`setStorage` function](#api) defined on the plugin. Unless set otherwise, state will be persisted on the `WP_DATA` key in storage. | ||
|
||
## Usage | ||
|
||
Call the `use` method on the default or your own registry to include the persistence plugin: | ||
|
||
```js | ||
wp.data.use( wp.data.plugins.persistence, { storageKey: 'example' } ); | ||
``` | ||
|
||
Then, when registering a store, set a `persist` property as `true` (persist all state) or an array of state keys to persist. | ||
|
||
```js | ||
wp.data.registerStore( 'my-plugin', { | ||
// ... | ||
|
||
persist: [ 'preferences' ], | ||
} ); | ||
``` | ||
|
||
## Options | ||
|
||
### `storage` | ||
|
||
Persistent storage implementation. This must at least implement `getItem` and `setItem` of the Web Storage API. | ||
|
||
See: https://developer.mozilla.org/en-US/docs/Web/API/Storage | ||
|
||
### `storageKey` | ||
|
||
The key on which to set in persistent storage. |
Oops, something went wrong.