This file contains 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 NwBuilder = require('nw-builder'), | |
buildsDir = 'c:/builds', | |
opts = { | |
files: './dist/**', // use the glob format | |
version: '0.12.0', | |
buildDir: buildsDir + '/build/', | |
cacheDir: buildsDir + '/cache/', | |
platforms: ['win64', 'osx64', 'linux64'] | |
}, | |
nw = new NwBuilder(opts); |
This file contains 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 Animal { | |
swim() { | |
console.log('swimming'); | |
} | |
eat() { | |
console.log('eating'); | |
} | |
sleep() { | |
console.log('sleeping'); | |
} |
This file contains 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 swimmer = (state) => ({ | |
swim: () => console.log(state.name, 'is swimming') | |
}) | |
const eater = (state) => ({ | |
eat: () => console.log(state.name, 'is eating') | |
}) | |
const sleeper = (state) => ({ | |
sleep: () => console.log(state.name, 'is sleeping') |
This file contains 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
// Design Patterns: Decorator | |
class Drink { | |
constructor() { | |
this.total = function() { | |
return 0; | |
} | |
} | |
} | |
// decorator 1 |
This file contains 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
let EventDispatcher = (function() { | |
let instance = null; | |
class EventDispatcher { | |
constructor() { | |
if(!instance) { | |
instance = this; | |
} | |
return instance; |
This file contains 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
export default class Game { | |
constructor(scenes) { | |
// check if the browser supports requestAnimationFrame | |
if(!(typeof requestAnimationFrame)) { | |
throw new Error('Your browser doesn\'t support requestAnimationFrame :('); | |
} | |
this.scenes = []; | |
this.addScenes(scenes); | |
this.play(); |
This file contains 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 Utils from './Utils'; | |
let assetLoaderInstance; | |
export default class AssetsLoader { | |
constructor() { | |
if(!assetLoaderInstance) { | |
console.log('AssetsLoader instance created'); | |
this.assets = {}; | |
assetLoaderInstance = this; |
This file contains 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
export default class Utils { | |
constructor() { | |
let e = new Error('is a static class, no need to instantiate!'); | |
e.name = 'Utils'; | |
throw e.toString(); | |
} | |
static toCamelCase(str) { | |
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(letter, index) { |
This file contains 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
let pubSubInstance; | |
const subjects = {}; | |
const hOP = subjects.hasOwnProperty; | |
class PubSub { | |
constructor() { | |
if(!pubSubInstance) { | |
console.log('EventDispatcher instance created'); | |
pubSubInstance = this; | |
} |
This file contains 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 { KeyboardEvents, EventDispatcher } from '../' | |
let keyboardInstance; | |
let keysMap = {}; | |
class KeyboardSingleton { | |
constructor() { | |
if(!keyboardInstance) { | |
console.log('Keyboard instance created'); | |
keyboardInstance = this; |
OlderNewer