Skip to content

Instantly share code, notes, and snippets.

View rolaveric's full-sized avatar

Jason Stone rolaveric

View GitHub Profile
@rolaveric
rolaveric / angularDirective.dart
Last active August 29, 2015 13:57
Simple example of a directive in AngularDart.
import 'dart:html';
import 'package:angular/angular.dart';
// Annotation which states that this class is a directive which should be
// attached to elements with a 'sample-text-id' attribute
@NgDirective(selector: '[sample-text-id]')
class ReverseClickDirective{
// The element that the directive is attached to
Element element;
@rolaveric
rolaveric / angularDependencyInjection.dart
Created March 29, 2014 11:08
Example of DI working in AngularDart.
// Simple class holding some configuration
class ConfigService{
String text;
ConfigService() {
this.text = "Meep!";
}
}
@NgDirective(selector: '[sample-text-id]')
class ReverseClickDirective{
@rolaveric
rolaveric / angularAnnotation.js
Created March 29, 2014 12:29
Example of how annotations look in Javascript post-traceur compilation.
/*
* @NgFilter(name: 'myfilter')
* function MyFilter() {}
*/
function MyFilter() {}
MyFilter.annotations = [new NgFilter({name: 'myFilter'})];
@rolaveric
rolaveric / protractorClickTest.js
Last active August 29, 2015 14:00
Simple protractor test which find an element, clicks it, then checks it's text value.
describe('click to reverse', function () {
var btn;
it('Reverses the button label on click', function () {
// load the page
browser.get('http://localhost:63342/protractorDemo/index.html');
// Find the button
btn = element(by.binding('click.btnText'));
@rolaveric
rolaveric / angular2Class.js
Created October 31, 2014 07:55
ES6 Class and equivalent ES5 code
// ES6 Class
class MyClass {
constructor() {
this.a = "b";
}
getA() {
return this.a;
}
}
@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 / 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'
}
});