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 { createSlimReduxStore } from 'slim-redux'; | |
// Create a store with initial state = 0 | |
var store = createSlimReduxStore(0); | |
// Make sure we see any store changes in the console | |
store.subscribe(() => | |
console.log(store.getState()) | |
) |
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
// Action constant (File #1) | |
// constants/ActionTypes.js | |
export const ADD_TODO = 'ADD_TODO' | |
// Action creator (File #2) | |
// actions/index.js | |
export const addTodo = text => ({ type: types.ADD_TODO, text }) | |
// Reducer (File #3) | |
// reducers/todos.js |
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
'ADD_TODO' constant (constants/ActionTypes.js) | |
| ↓ | |
| 'todos' reducer (reducers/todo.js) | |
| ↓ | |
| 'rootReducer' (reducers/index.js) | |
| | |
↓ | |
'addTodo' action creator (actions/index.jx) | |
| | |
↓ |
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
-- ********************************************* | |
-- demonstrate how to get the program parameters | |
-- ********************************************* | |
local internal_name = select(1,...); | |
local visible_name = select(2,...); | |
gma.echo("Hello, you loaded the plugin " .. internal_name); -- you will see this message in the system monitor | |
-- ********************************************* |
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
// Taken from: | |
// http://stackoverflow.com/questions/24464404/how-to-readline-infinitely-in-node-js | |
const readline = require('readline'); | |
var log = console.log; | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); |
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 stuff = require('stuff'); | |
var exp = { | |
someFunction: function(param1, param2) { | |
// Do Stuff | |
}, | |
someOtherFunction: function(param1, param2, param3) { | |
this.someFunction('this', 'that'); | |
} |
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
// Source: http://stackoverflow.com/questions/684672/how-do-i-loop-through-or-enumerate-a-javascript-object | |
for (var key in p) { | |
if (p.hasOwnProperty(key)) { | |
console.log(key + " -> " + p[key]); | |
} | |
} |
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
process.stdin.resume();//so the program will not close instantly | |
function exitHandler(options, err) { | |
if (options.cleanup) console.log('clean'); | |
if (err) console.log(err.stack); | |
if (options.exit) process.exit(); | |
} | |
//do something when app is closing | |
process.on('exit', exitHandler.bind(null,{cleanup:true})); |
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 Promise = require('promise'); | |
var fs = require('fs'); | |
var write = Promise.denodeify(fs.writeFile) | |
// Example #1: Using promisified functions | |
// Important!! .then() and .catch() need to be passed in a function! | |
var promise = write('bla.txt', 'Blablabla', 'utf-8') | |
.then(function(){console.log('Success!')}) |
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
function getType (thing) { | |
switch (Object.prototype.toString.call(thing)) { | |
case '[object Object]': | |
return 'object' | |
break | |
case '[object Array]': | |
return 'array' | |
break |