Skip to content

Instantly share code, notes, and snippets.

View arqex's full-sized avatar
💭
Bootstraping project faster allows to do more things!

Javier Marquez arqex

💭
Bootstraping project faster allows to do more things!
View GitHub Profile
@arqex
arqex / messageLoadReaction.js
Created May 16, 2017 07:51
Message load reactio
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
});
@arqex
arqex / Messages.js
Created May 16, 2017 07:54
Messages component
class Messages extends React.Component({
render(){
if( this.props.store.status === 'LOADING' ){
return this.renderLoading();
}
else {
return this.renderReady();
}
}
});
@arqex
arqex / messageReaction2.js
Created May 16, 2017 08:00
Message reaction 2
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
@arqex
arqex / returningReaction.js
Last active May 16, 2017 14:53
Returning reaction
// 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)
@arqex
arqex / messageReceivedEvent.js
Created May 16, 2017 21:49
Message receive
// 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 );
})
@arqex
arqex / socketEventHub.js
Last active May 16, 2017 22:09
Socket event hub
// 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');
@arqex
arqex / installPassPillServer
Created February 26, 2018 18:10
Installing Passpill server
git clone https://github.com/passpill-io/passpill-backend.git
cd passpill-backend
npm install
npm start
@arqex
arqex / webpack.config.js
Last active April 15, 2018 12:22
DefinePlugin
var webpack = require("webpack");
// ...
{
// ...
plugins: [
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
})
]
// ...
@arqex
arqex / config.js
Created April 15, 2018 11:27
Config using NODE_ENV
const config = {}
if( process.env.NODE_ENV === 'production' ){
config.remoteURL = 'http://myserver.com/resource';
}
else {
config.remoteURL = 'http://localhost/resource';
}
export default config;
@arqex
arqex / webpack.config.js
Created April 15, 2018 12:09
Webpack copy plugin
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