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
// Standard Service Class | |
export class MyService { | |
constructor(private config) { } | |
} | |
// factory for creating new instances of the service | |
function createMyService(config = {}) { | |
return new MyService(config); | |
} |
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 { Injectable } from '@angular/core'; | |
import { Subject } from 'rxjs/Subject'; | |
@Injectable() | |
export class AppStateService { | |
changes: Subject<any> = new Subject(); | |
private state: any = {}; | |
private history: any[] = []; | |
private historyPos: number = 0; |
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 fallback = require('express-history-api-fallback'); | |
var express = require('express'); | |
var compress = require('compression'); | |
var app = express(); | |
var root = __dirname + '/dist'; | |
app.use(compress()); | |
app.use(express.static(root)); | |
app.use(fallback('index.html', { root: root })); |
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 myWorker = $worker().create(function () { | |
self.postMessage('Hello World'); | |
}); | |
myWorker.run().then(function (e) { | |
console.log(e.data); // 'Hello World' | |
}); |
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 myWorker = createWorker(function (e) { | |
self.postMessage(e.data.toUpperCase()); | |
}); | |
myWorker.onMessage = function (e) { | |
console.log(e.data); // HELLO FROM AN INLINE WORKER! | |
} | |
myWorker.postMessage('hello from an inline worker!') |
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
// New workers is created for a link to an external js file | |
var myWorker = new Worker('web-worker.js'); | |
// function to fire when a message is sent from the worker. | |
myWorker.onmessage = function (e) { | |
console.log(e.data); // HELLO WORLD | |
} | |
// send a message to the worker | |
myWorker.postMessage('hello world'); |
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
function createWorker(fn) { | |
var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' }); | |
var url = URL.createObjectURL(blob); | |
return new Worker(url); | |
} |
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
function $worker() { | |
var workers = []; | |
// PUBLIC_API | |
return { | |
create: create, | |
runAll: runAll, | |
terminateAll: terminateAll, | |
list: list | |
} |
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
/* global require, module */ | |
var Angular2App = require('angular-cli/lib/broccoli/angular2-app'); | |
const vendorNpmFiles = [ | |
'systemjs/dist/system-polyfills.js', | |
'systemjs/dist/system.src.js', | |
'zone.js/dist/**/*.+(js|js.map)', | |
'es6-shim/es6-shim.js', | |
'reflect-metadata/**/*.+(js|js.map)', |
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 {Pipe, PipeTransform} from '@angular/core'; | |
import * as moment from 'moment'; | |
@Pipe({ | |
name: 'moment' | |
}) | |
export class MomentPipe implements PipeTransform { | |
transform(date, format) { | |
return moment(date).format(format); | |
} |