2017-11-13 11:21:11 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { kea } from 'kea'
|
|
|
|
|
|
|
|
@kea({
|
|
|
|
path: () => ['kea'],
|
|
|
|
actions: () => ({
|
|
|
|
increment: amount => ({ amount }),
|
|
|
|
decrement: amount => ({ amount })
|
|
|
|
}),
|
|
|
|
reducers: ({ actions }) => ({
|
|
|
|
counter: [
|
|
|
|
0,
|
|
|
|
PropTypes.number,
|
|
|
|
{
|
|
|
|
[actions.increment]: (state, payload) => state + payload.amount,
|
|
|
|
[actions.decrement]: (state, payload) => state - payload.amount
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
selectors: ({ selectors }) => ({
|
|
|
|
doubleCounter: [
|
|
|
|
() => [selectors.counter],
|
|
|
|
counter => counter * 2,
|
|
|
|
PropTypes.number
|
|
|
|
]
|
|
|
|
})
|
|
|
|
})
|
2018-09-23 14:01:37 +00:00
|
|
|
|
|
|
|
export default class App extends React.Component {
|
2017-11-13 11:21:11 +00:00
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<p>Double Counter: {this.props.doubleCounter}</p>
|
|
|
|
<button type='button' onClick={() => this.actions.increment(1)}>Increment</button>
|
|
|
|
<button type='button' onClick={() => this.actions.decrement(1)}>Decrement</button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|