New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proppy: add `onChange` function #4

Merged
merged 3 commits into from Jun 2, 2018

Conversation

1 participant
@fahad19
Copy link
Owner

fahad19 commented Jun 2, 2018

API

onChange(propName, (prop, providers) => props)

onChange(
(prevProps, nextProps) => true,
(props, providers) => props
)

Detect a change in props, and return new props.

Examples:

Change foo, when counter changes:

const P = compose(
  withProps({ foo: 'initial foo value' })
  withState('counter', 'setCounter', 0),
  onChange('counter', (props, providers) => ({
    foo: `changed foo with counter ${props.counter}`
  }))
);

const p = P();
console.log(p.props.foo); // `initial foo value`

p.props.setCounter(10);
console.log(p.props.foo); // `changed foo with counter 10`

Detecting complex changes:

const P = compose(
  withState('counter', 'setCounter', 0),
  onChange(
    // detect
    (prevProps, nextProps) => true,

    // return props
    (props, providers) => props
  )
);

fahad19 added some commits Jun 2, 2018

@fahad19 fahad19 self-assigned this Jun 2, 2018

@fahad19 fahad19 added PR minor labels Jun 2, 2018

@fahad19 fahad19 merged commit 8da847e into master Jun 2, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@fahad19 fahad19 deleted the onChange branch Jun 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment