# react-push-channel

> React Context from reverse.

Latest version **0.0.3** (published 2018-08-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-push-channel
pnpm add react-push-channel
yarn add react-push-channel
bun add react-push-channel
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2018-08-16 |
| First published | 2018-08-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.5.0 |
| Dependencies | 0 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Anton Korzunov |
| Maintainers | kashey |
| Keywords | react, context, channel, helmet, event |

## Links

- npm: https://www.npmjs.com/package/react-push-channel
- Homepage: https://github.com/theKashey/react-push-channel#readme
- npm.io page: https://npm.io/package/react-push-channel

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2018-08-16
- 0.0.2 — 2018-08-15
- 0.0.1 — 2018-08-15

## README

# react-push-channel 
[![CircleCI status](https://img.shields.io/circleci/project/github/theKashey/react-push-channel/master.svg?style=flat-square)](https://circleci.com/gh/theKashey/react-push-channel/tree/master)
[![Greenkeeper badge](https://badges.greenkeeper.io/theKashey/react-push-channel.svg)](https://greenkeeper.io/)

----

[![NPM](https://nodei.co/npm/react-push-channel.png?downloads=true&stars=true)](https://nodei.co/npm/react-push-channel/) 

Context is to drill props down. React Push Channel drill props up.

# API
#### `createChannel(initialValue, reducer?, initialValueForReducer?)`
creates a channel, with given initialValue(used for typing), and optional reducer.
Reducer will be applied to all stored `messages`, producing the result.

createChannel return an object with 3 fields:
 - `Collector` - to collect all messages. 
    - `callback` - current value will be reported via callback.
    - `[merge]` - enabled reducer on data. Ie merges everything into a single value. Otherwise would return last value.
 - `Push` - put message into the channel
    - any props from initialValue
 - `Pop` - react the current active message      

## Use as React-helmet?

```js
import {createChannel} from 'react-push-channel';

const helmet = createChannel({
  title: '',
  description: ''
});

// the root collector
<helmet.Collector 
  callback={helmet => this.setState({helmet})} // transfer reported info into the state 
  merge                                        // merge all data in reverse order 
>
   <helmet.Push title="Page Title"/>
   <helmet.Push description="Page description"/>
</helmet.Collector>

// or actually do the job

<helmet.Collector 
  callback={helmet => document.title=helmet.title} // actually SET THE TITLE! 
  merge                                         
>
   <helmet.Push title="Page Title"/>
   <helmet.Push description="Page description"/>
</helmet.Collector
```

## React-Lock

This example uses reducer to basically calculate number or active locks, and `Pop`
to read active value down the tree.
```js
const Lock = createChannel({}, acc => acc + 1, 0);

<Lock.Collector merge callback={locked => this.setState({locked: !!locked})}>
  <Lock.Push />
  <Lock.Pop>{locked => <span> is {locked?'locked':'unlocked'}</Lock.Pop>
</Lock.Collector>  


# Licence
 MIT

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