-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Data: Add persistence via data plugin interface #8341
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
17a9f51
Data: Add persistence via data plugin interface
aduth 27c1ba3
Data: Integrate persistence as first-party plugin
aduth 03e4cb4
Data: Restore deprecated persistence behaviors
aduth f0f8c07
Data: Return default persisted by caught error
aduth 0b6c37f
Data: Initialize persistence by plugin options
aduth 2dacdf1
Data: Remove string form variation on use
aduth 4219594
Data: Refactor persistence as dispatch enhancer
aduth f00c9f5
Data: Remove middlewares / enhancers support for store
aduth b3d13dc
Data: Remove unused variable
aduth 2085eed
Data: Improve objectStorage spec compliancy
aduth 94a1f4c
Data: Fix persistence handling of null value
aduth 8f8c544
Data: Fix deprecation key to persist
aduth 4f630b1
Data: Add tests for WPDataRegistry#use
aduth e4a1c0e
Data: Remove _ prefix from local variable
aduth fdc8938
Data: Update plugins documentation to avoid mention of string usage
aduth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This simplifies a lot in terms of passing user id to the client 👍