https://github.com/cyclejs/storage
A Cycle.js Driver for using localStorage and sessionStorage.
https://github.com/cyclejs/storage
Last synced: about 2 months ago
JSON representation
A Cycle.js Driver for using localStorage and sessionStorage.
- Host: GitHub
- URL: https://github.com/cyclejs/storage
- Owner: cyclejs
- License: mit
- Created: 2015-11-09T14:37:05.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-12-17T20:24:14.000Z (over 4 years ago)
- Last Synced: 2025-04-27T14:27:02.797Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 208 KB
- Stars: 51
- Watchers: 5
- Forks: 13
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Cycle Storage Driver
A [Cycle.js](http://cycle.js.org) [Driver](http://cycle.js.org/drivers.html) for using
[localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) and
[sessionStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)
in the browser.```
npm install --save @cycle/storage
```## Usage
You can read the [API docs here](https://github.com/kahlil/cycle-storage-driver/blob/master/docs/api.md).
Basics:
```js
import Cycle from '@cycle/core';
import storageDriver from '@cycle/storage';function main(responses) {
// ...
}const drivers = {
storage: storageDriver
}Cycle.run(main, drivers);
```Simple and normal use case ([JSBin demo](http://jsbin.com/xumuqi/15/edit?html,js,console,output)):
```js
function main({DOM, storage}) {
const storageRequest$ = DOM.select('input')
.events('keypress')
.map(function(ev) {
return {
key: 'inputText',
value: ev.target.value
};
});return {
DOM: storage.local
.getItem('inputText')
.startWith('')
.map((text) =>
h('input', {
type: 'text',
value: text
})
),
storage: storageRequest$
};
}
```# License
[MIT](https://github.com/kahlil/cycle-storage-driver/blob/master/LICENSE)