Skip to content

Instantly share code, notes, and snippets.

View robertpenner's full-sized avatar

Robert Penner robertpenner

View GitHub Profile
@robertpenner
robertpenner / basicreduce.js
Created October 21, 2013 11:00
Functional JavaScript Workshop Solutions
function countWords(inputWords) {
return inputWords.reduce(function(counts, word) {
counts[word] = (counts[word] || 0) + 1;
return counts;
}, {})
}
module.exports = countWords
@robertpenner
robertpenner / config.js
Last active March 17, 2016 04:29 — forked from johnlindquist/config.js
Angular 2 RxJS TypeWriter
System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true
},
//map tells the System loader where to look for things
map: {
app: "./src",
@robertpenner
robertpenner / config.js
Created March 17, 2016 04:32 — forked from johnlindquist/config.js
angular 2 with sagas and reducers
System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true
},
//map tells the System loader where to look for things
map: {
app: "./src",
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RxJSCraft</title>
<script src="https://npmcdn.com/systemjs@0.19.24/dist/system.js"></script>
<script src="https://npmcdn.com/typescript@1.8.9/lib/typescript.js"></script>
<script src="https://npmcdn.com/rxjs@5.0.0-beta.4/bundles/Rx.js"></script>
<style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RxJSCraft</title>
<script src="https://npmcdn.com/systemjs@0.19.24/dist/system.js"></script>
<script src="https://npmcdn.com/typescript@1.8.9/lib/typescript.js"></script>
</head>
SystemJS.config({
transpiler: "typescript",
typescriptOptions: {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
map: {
"rxjs": "https://npmcdn.com/rxjs",
"angular2": "https://npmcdn.com/angular2",
"@ngrx": "https://npmcdn.com/@ngrx",

Angular2 + JSPM cheat sheet

First time setup

  • install jspm beta: npm install -g jspm@beta
  • set up your project: jspm init
  • install dependencies: jspm install angular2 reflect-metadata zone.js es6-shim

This will create a jspm_packages folder, and a config.js file.

Open the config.js file - this file manages options for the System.js loader - tweak it as appropriate

[] + []; // JavaScript will give you "" (which makes little sense), TypeScript will error
//
// other things that are nonsensical in JavaScript
// - don't give a runtime error (making debugging hard)
// - but TypeScript will give a compile time error (making debugging unnecessary)
//
{} + []; // JS : 0, TS Error
[] + {}; // JS : "[object Object]", TS Error
{} + {}; // JS : NaN, TS Error
@robertpenner
robertpenner / functional-utils.js
Created March 15, 2017 02:01 — forked from bendc/functional-utils.js
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@robertpenner
robertpenner / README.md
Created March 17, 2016 04:24 — forked from johnlindquist/README.md
Angular 2 Clock

Angular2 Starter Gist Run