Skip to content

Instantly share code, notes, and snippets.

@nicolashery
Created June 2, 2015 16:09
Show Gist options
  • Save nicolashery/5c6e8da186dad8915c2f to your computer and use it in GitHub Desktop.
Save nicolashery/5c6e8da186dad8915c2f to your computer and use it in GitHub Desktop.
// https://github.com/gaearon/redux
// example/Counter.js
import React from 'react';
import { performs, observes } from 'redux';
// Explicit import of stores/actions so you know what your component depends on
// (could also be useful for some static analysis tool?)
import { increment, decrement } from './actions';
import { CounterStore } from './stores';
@performs(increment, decrement)
@observes(CounterStore)
export default class Counter {
render() {
const { increment, decrement } = this.props;
return (
<p>
Clicked: {this.props.counter} times
{' '}
<button onClick={() => increment()}>+</button>
{' '}
<button onClick={() => decrement()}>-</button>
</p>
);
}
}
// src/observes.js
// ...
export default function connect(...storeKeys) {
// ...
storeKeys = storeKeys.map(key => {
if (typeof key === 'string') {
return key;
} else {
invariant(key.name.length, 'Must give store function a name');
return key.name;
}
});
// ...
}
// similar for src/performs.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment