Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.