# cycle-cookie-driver

> A cookie driver for Cycle.js

Latest version **1.0.2** (published 2017-02-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install cycle-cookie-driver
pnpm add cycle-cookie-driver
yarn add cycle-cookie-driver
bun add cycle-cookie-driver
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2017-02-10 |
| First published | 2017-02-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Timur Kiyivinski |
| Maintainers | timurkiyivinski |
| Keywords | cycle, cookie, xstream, driver |

## Links

- npm: https://www.npmjs.com/package/cycle-cookie-driver
- Repository: https://github.com/TimurKiyivinski/cycle-cookie-driver
- Homepage: https://github.com/TimurKiyivinski/cycle-cookie-driver#readme
- Issues: https://github.com/TimurKiyivinski/cycle-cookie-driver/issues
- npm.io page: https://npm.io/package/cycle-cookie-driver

## Dependencies (2)

- [xstream](https://npm.io/package/xstream.md) ^10.2.0
- [js-cookie](https://npm.io/package/js-cookie.md) ^2.1.3

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2017-02-10
- 1.0.1 — 2017-02-08
- 1.0.0 — 2017-02-08

## README

# cycle-cookie-driver
Cookie driver for Cycle.js that wraps around [js-cookie](https://github.com/js-cookie/js-cookie).

## installation
Install with NPM
```bash
npm install --save cycle-cookie-driver
```

## usage
Import into your ES6 code:
```javascript
import { makeCookieDriver } from 'cycle-cookie-driver'
```
Register the driver:
```javascript
const drivers = {
  ...
  cookie: makeCookieDriver()
}
```
Request format for `cookie` sink:
```javascript
{
  category: 'getCounter',
  action: 'get',
  params: ['counter']
}
```
All requests wrap around `js-cookie` methods, hence `get, getJSON, set, remove` methods along with all arguments are supported.
Params are applied to the `Cookie` instance as so: 
```javascript
const data = Cookies[action](...params)
```
The data received is passed to an optional callback, for example:
```javascript
const getCounterCookie$ = sources.cookie.select('getCounter')
```

## sample
As there is no cookie `onchange` event from the browser, the only way to check for updates is to periodically poll a cookie.
```javascript
import xs from 'xstream'
import { div, p } from '@cycle/dom'

const HomeComponent = sources => {
  const getCounterCookie$ = sources.cookie.select('getCounter')

  const counterGetCookie$ = xs.periodic(5000).mapTo({
    category: 'getCounter',
    action: 'get',
    params: ['counter']
  })

  const counterSetCookie$ = xs.periodic(1000).map(count => ({
    category: 'setCounter',
    action: 'set',
    params: ['counter', count]
  }))

  const cookie$ = xs.merge(counterGetCookie$, counterSetCookie$)

  const vdom$ = getCounterCookie$.map(cookie => {
    return div([
      p(cookie)
    ])
  })

  return {
    DOM: vdom$,
    cookie: cookie$
  }
}

export default HomeComponent
```

---
_Source: https://npm.io/package/cycle-cookie-driver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
