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
| 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', () => { | |
| 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
| // 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
| // 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
| // This helper will guide our websocket events to freezer | |
| function toFreezer( socketEvent, freezerEvent ){ | |
| socket.on( socketEvent, function(){ | |
| var args = [freezerEvent].concat( Array.from(arguments) ); | |
| freezer.emit.apply( freezer, args ); | |
| }); | |
| } | |
| // Now we can redirect socket events easily | |
| toFreezer('messageReceived', 'message:received'); |
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
| git clone https://github.com/passpill-io/passpill-backend.git | |
| cd passpill-backend | |
| npm install | |
| npm start |
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
| var webpack = require("webpack"); | |
| // ... | |
| { | |
| // ... | |
| plugins: [ | |
| new webpack.DefinePlugin({ | |
| "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV) | |
| }) | |
| ] | |
| // ... |
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 config = {} | |
| if( process.env.NODE_ENV === 'production' ){ | |
| config.remoteURL = 'http://myserver.com/resource'; | |
| } | |
| else { | |
| config.remoteURL = 'http://localhost/resource'; | |
| } | |
| export default config; |
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
| var Copy = require('copy-webpack-plugin'); | |
| // ... | |
| { | |
| // ... | |
| plugins: [ | |
| new Copy({ | |
| from: 'assets/fonts', | |
| to: 'fonts', // path relative to the build folder | |
| toType: 'dir', // or 'file' | |
| ignore: ['*.json'] // We can skip files |