Skip to content

Instantly share code, notes, and snippets.

View rolaveric's full-sized avatar

Jason Stone rolaveric

View GitHub Profile
@rolaveric
rolaveric / angular2Type.js
Last active August 29, 2015 14:08
Type syntax from TypeScript
// TypeScript types
function myFn(name:string, obj:MyClass) {
// ...
}
// Equivalent ES5
/**
* @param name {string}
* @param obj {MyClass}
*/
@rolaveric
rolaveric / angular2TypeIntrospection.js
Created October 31, 2014 09:05
Type Introspection from AtScript
// AtScript types
function myFn(name:string, obj:MyClass) {
// ...
}
// Equivalent ES5
/**
* @param name {string}
* @param obj {MyClass}
*/
@rolaveric
rolaveric / angular2Annotations.js
Created October 31, 2014 09:39
Annotations from AtScript
// Annotation in AtScript
@MyAnnotation({a: 'b'})
function fn() {}
// Equivalent ES5
function fn() {}
fn.annotations = [new MyAnnotation({a: 'b'})];
@rolaveric
rolaveric / angular2ControllerDirective.js
Created November 5, 2014 09:42
AngularJS v1.3 equivalent of controller replacement in Angular v2.0
angular.module('myApp', []).directive('myComponent', function() {
return {
scope: true,
controller: function() {
this.myProperty = 'myValue';
this.myMethod = function() {
return 'myResult';
};
},
controllerAs: 'myComponent'
@rolaveric
rolaveric / systemjsAsync.html
Last active August 29, 2015 14:13
HTML for loading modules through SystemJS asynchronously
<script src="bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js"></script>
<script src="bower_components/traceur/traceur.js"></script>
<script src="bower_components/es6-module-loader/dist/es6-module-loader.js"></script>
<script src="bower_components/system.js/dist/system.js"></script>
<script src="system.config.js"></script>
<script>
System.import('app').then(function() {
angular.bootstrap(document, ['myApp']);
});
@rolaveric
rolaveric / system.config.js
Last active August 29, 2015 14:13
Example of a SystemJS configuration file
// Configure module loader
System.config({
baseURL: '/app/',
// Set paths for third-party libraries as modules
paths: {
'angular': 'bower_components/angular/angular.js',
'angular-route': 'bower_components/angular-route/angular-route.js'
}
});
@rolaveric
rolaveric / es6Imports.js
Last active August 29, 2015 14:13
Example of declaring all module imports with ES6
'use strict';
import 'angular';
import 'angular-route';
import './components/version/version';
import './components/version/interpolate-filter';
import './components/version/version-directive';
import './view1/view1';
import './view2/view2';
// Declare app level module which depends on views, and components
@rolaveric
rolaveric / bundle.js
Created January 21, 2015 10:04
Example of how to bundle ES6 modules using systemjs-builder for production
var builder = require('systemjs-builder'),
path = require('path');
// load SystemJS config from file
builder.loadConfig('./app/system.config.js')
.then(function() {
// Change baseURL to match the file system
builder.config({ baseURL: path.resolve('./app') });
// Build a self-executing bundle (ie. Has SystemJS built in and auto-imports the 'app' module)
@rolaveric
rolaveric / es6Bundle.html
Created January 21, 2015 10:06
Example HTML for loading a bundle from systemjs-builder
<script src="bower_components/traceur-runtime/traceur-runtime.min.js"></script>
<script src="bundle.js"></script>
@rolaveric
rolaveric / karma-systemjs.conf.js
Created January 21, 2015 10:07
Snippet of a Karma configuration using karma-systemjs
// Add 'karma-systemjs' to the list of plugins
plugins: ['karma-systemjs', ...],
// Add 'systemjs' to the list of frameworks
frameworks: ['systemjs', 'jasmine'],
// Move all the `files` to `systemjs.files`
files: [],
systemjs: {