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
// In our socket event handlers file | |
socket.on('messageReceived', message => { | |
freezer.emit('message:received', message); | |
}); | |
// In our message reactions file | |
freezer.on('message:received', message => { | |
freezer.get().messages.push( message ); | |
}) |
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
// We can return the promise from our reaction | |
freezer.on('message:send', text => { | |
freezer.get().set({status: 'SENDING'}); | |
// Return the promise | |
return Ajax.post('/messages', {text: text} ) | |
.then( msg => { | |
freezer.get() | |
.set({status: 'READY'}) | |
.messages.push(msg) |
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
freezer.on('message:loadAll', () => { | |
freezer.get().set({status: 'LOADING'}); | |
Ajax.get('/messages').then( messages => { | |
freezer.get.set({ | |
status: 'READY', | |
messages: messages | |
}); | |
// Some other reactions might be listening to this |
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
class Messages extends React.Component({ | |
render(){ | |
if( this.props.store.status === 'LOADING' ){ | |
return this.renderLoading(); | |
} | |
else { | |
return this.renderReady(); | |
} | |
} | |
}); |
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
freezer.on('message:loadAll', () => { | |
// Let the app know we are loading stuff | |
freezer.get().set({status: 'LOADING'}); | |
Ajax.get('/messages').then( messages => { | |
freezer.get.set({ | |
status: 'READY', // We are ready again! | |
messages: messages | |
}); |
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
const me = () => freezer.get().me; | |
freezer.on( 'user:update', update => { | |
me().set({name: update.name}); | |
if( update.hobbies ){ | |
me().set({hobbies: update.hobbies}); | |
} | |
}); |
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
// I call the helper `d` after the concept `domain`. | |
const d = () => freezer.get().user; | |
freezer.on('user:create', user => { | |
d().set(user.id, user); | |
}); | |
freezer.on('user:update', (id, update) => { | |
d()[id].set(update); | |
}); |
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
freezer.on('user:update', update => { | |
var me1 = freezer.get().me; | |
var me2 = me.set({name: update.name}); | |
if( update.hobbies ){ | |
me2.set({hobbies: update.hobbies}); | |
} | |
} |
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
freezer.on( 'user:update', update => { | |
var me1 = freezer.get().me; | |
me1.set({name: update.name}); | |
if( update.hobbies ){ | |
me1.set({hobbies: update.hobbies}); | |
} | |
}); |
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
freezer.on('user:create', user => { | |
freezer.get().users.set(user.id, user); | |
}); | |
freezer.on('user:update', (id, update) => { | |
freezer.get().users[id].set(update); | |
}); | |
freezer.on('user:delete', id => { | |
freezer.get().users.remove(id); |