Created
June 2, 2015 16:09
-
-
Save nicolashery/5c6e8da186dad8915c2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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