Add-ons functions for use with Raid
npm install raid-addons> Addons and helpers for use with raid





``sh`
yarn add raid raid-addons
`sh`
npm i -S raid raid-addons
Raid does one job, it helps to manage the state of your application. It does this job simply enough but sometimes you want to add some sugar or some extra _stuff_ for tasks you typically do often.
This is a disparate list of add-ons and whilst they were created with Raid in mind they could equally be used with other libraries. They are typically small utility functions and often best used composed together.
See the examples for more detailed usage.
(
An adaptor can be attached to a signal and returns a function that can be used to create a higher-order component that has data from the state provided to it, that data will be passed as props.
`js
const signal = new Signal({
title: 'Foo'
})
const connect = adaptor(Signal)
const El = ({title}) =>
The returned
connect function should be supplied with a selector function (which is responsible for grabbing parts of the state) and a component function.The state selector function is optional and the component function will become the first argument if omitted.
* Libraries like reselect, which help to create the selector function for you, work great with this pattern.
> The source uses JSX to pass through the
Component and is currently building only for use with React.$3
(A plug is functionally identical to
adaptor, but without the property massaging to be used any component specification i.e. it can be used with raw functions instead.Plug returns a
connect function which can be used to decorate a function and pass through state from a Raid Signal.`js
const signal = new Signal({
foo: 'hello'
})
const connect = plug(signal)const hof = (
state => state.foo,
(state, passed) => {
console.log(state, ':', passed)
}
)
hof('world')
// hello : world
`$3
(