Last active
October 9, 2016 12:17
-
-
Save TheRusskiy/48e877e20b969cbf4ee107df3b2d98f4 to your computer and use it in GitHub Desktop.
pusher-redux examples https://github.com/TheRusskiy/pusher-redux
This file contains hidden or 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
return { | |
type: actionType, | |
channel: channelName, | |
event: eventName, | |
data: data | |
}; |
This file contains hidden or 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
import { configurePusher } from 'pusher-redux'; | |
... | |
const options = { // options are... optional | |
authEndpoint: '/authenticate/me' | |
} | |
const store = configureStore(initialState); | |
configurePusher(store, API_KEY, options); |
This file contains hidden or 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
import { subscribe, unsubscribe } from 'pusher-redux'; | |
import { NEW_ORDER } from '../pusher/constants'; | |
... | |
export class MyPage extends React.Component { | |
constructor(props, context) { | |
super(props, context); | |
this.subscribe = this.subscribe.bind(this); | |
this.unsubscribe = this.unsubscribe.bind(this); | |
} | |
componentWillMount() { | |
this.subscribe(); | |
} | |
componentWillUnmount() { | |
this.unsubscribe(); | |
} | |
// upon receiving event 'some_event' for channel 'some_channe' pusher-redux is going to dispatch action NEW_ORDER | |
// you can bind multiple actions for the same event and it's gonna dispatch all of them | |
subscribe() { | |
subscribe('some_channel', 'some_event', NEW_ORDER); | |
} | |
unsubscribe() { | |
unsubscribe('some_channel', 'some_event', NEW_ORDER); | |
} | |
... | |
} |
This file contains hidden or 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
import { NEW_ORDER } from '../pusher/constants'; | |
... | |
function orderReducer(state = initialState.orders, action) { | |
case NEW_ORDER: | |
return [...state, action.data.order]; | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment