reshep
A higher-order component that "reshapes" a React component props object.
Last updated 3 years ago by maxhallinan .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install reshep 
SYNC missed versions from official npm registry.

reshep

Build Status Coverage Status

A higher-order component that "reshapes" a React component props object according to a map of from/to path strings.

An alternative to a map function when no value transformation is required.

Install

$ npm install --save reshep

Usage

import assert from 'assert';
import { shapeFrom, } from 'reshep';

const enhance = shapeFrom({
  'history.push': 'changeRoute',
  'match.params.foo': 'foo',
});

const Foo = enhance(({ changeRoute, foo, }) => {
  assert.ok(changeRoute);
  assert.ok(foo);

  /* ... */
});
import assert from 'assert';
import { shapeWith, } from 'reshep';

const enhance = shapeWith({
  'match.params.foo': 'foo',
});

const Foo = enhance(({ match, foo, }) => {
  assert.ok(foo);

  // parent props are merged with new props
  assert.ok(match.params.foo);

  /* ... */
});

API

shapeFrom(pathMap)

Takes a map of path strings and returns a higher-order component. The higher-order component picks values from the parent props and sets them on a new props object passed to the base component.

pathMap

Type: { [string]: string }

An object map of path strings. The key is a path to pick from the parent props and the value is a path to set on the base component props.

shapeWith(pathMap)

Like shapeFrom, except the new props are deeply merged with the parent props.

pathMap

The same as the pathMap argument to shapeFrom.

License

MIT © Max Hallinan

Current Tags

  • 1.0.4                                ...           latest (3 years ago)

8 Versions

  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.1.3                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 9
Dependencies (0)
None
Dev Dependencies (48)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |