Skip to content

Commit

Permalink
refactor: move rtts-assert into modules directory
Browse files Browse the repository at this point in the history
The rtts assertion lib is only needed for js, 
but it should be treated like any other module (e.g. facade, …)
  • Loading branch information
tbosch committed Sep 27, 2014
1 parent c3b442e commit c8cf03f
Show file tree
Hide file tree
Showing 9 changed files with 789 additions and 10 deletions.
7 changes: 2 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var js2es5Options = {
types: true, // parse types
script: false, // parse as a module
modules: 'register',
typeAssertionModule: 'assert',
typeAssertionModule: 'rtts_assert/rtts_assert',
typeAssertions: true
};

Expand Down Expand Up @@ -52,12 +52,9 @@ gulp.task('jsRuntime/build', function() {

function createJsRuntimeTask(isWatch) {
var srcFn = isWatch ? watch : gulp.src.bind(gulp);
var rttsAssert = srcFn('tools/rtts-assert/src/assert.js')
.pipe(gulpTraceur(js2es5Options, resolveModuleName))
.pipe(gulp.dest('build/js'));
var traceurRuntime = srcFn(gulpTraceur.RUNTIME_PATH)
.pipe(gulp.dest('build/js'));
return mergeStreams(rttsAssert, traceurRuntime);
return traceurRuntime;
}

// -----------------------
Expand Down
5 changes: 2 additions & 3 deletions karma-js.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ module.exports = function(config) {
script: false,
modules: 'register',
types: true,
// TODO: turn this on!
// typeAssertions: true,
// typeAssertionModule: 'assert',
typeAssertions: true,
typeAssertionModule: 'rtts_assert/rtts_assert',
annotations: true
},
resolveModuleName: function(fileName) {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class View {

onRecordChange(record:Record, target) {
// dispatch to element injector or text nodes based on context
if (target is ElementInjectorTarge) {
if (target instanceof ElementInjectorTarge) {
// we know that it is ElementInjectorTarge
var eTarget:ElementInjectorTarget = target;
onChangeDispatcher.notify(this, eTarget);
Expand Down
44 changes: 44 additions & 0 deletions modules/rtts_assert/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Asserting APIs:
// - generated by Traceur (based on type annotations)
// - can be also used in tests for instance
assert.type(something, Type);
assert.returnType(returnValue, Type);
assert.argumentTypes(firstArg, Type, secondArg, Type);

// this can be used anywhere in the code
// (useful inside test, when we don't wanna define an interface)
assert(value).is(...)


// Custom type assert:
// - i have a custom type
// - adding an assert methos
assert.define(MyUser, function(value) {
assert(value).is(Type, Type2); // or
assert(value, 'name').is(assert.string);
assert(value, 'contact').is(assert.structure({
email: assert.string,
cell: assert.string
}));
assert(value, 'contacts').is(assert.arrayOf(assert.structure({email: assert.string})));
});



// Define interface (an empty type with assert method)
// - returns an empty class with assert method
var Email = assert.define('IEmail', function(value) {
assert(value).is(String);

if (value.indexOf('@') !== -1) {
assert.fail('has to contain "@"');
}
});


// Predefined types
assert.string
assert.number
assert.boolean
assert.arrayOf(...types)
assert.structure(object)
1 change: 1 addition & 0 deletions modules/rtts_assert/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://angular.github.io/assert/
31 changes: 31 additions & 0 deletions modules/rtts_assert/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "rtts-assert",
"version": "0.0.1",
"description": "A type assertion library for Traceur.",
"main": "./dist/cjs/assert.js",
"homepage": "https://github.com/angular/assert",
"repository": {
"type": "git",
"url": "git://github.com/angular/assert.git"
},
"bugs": {
"url": "https://github.com/angular/assert/issues"
},
"dependencies": {},
"devDependencies": {
"gulp": "^3.5.6",
"gulp-connect": "~1.0.5",
"gulp-traceur": "~0.4.0",
"karma": "^0.12.1",
"karma-chrome-launcher": "^0.1.2",
"karma-jasmine": "^0.2.2",
"karma-requirejs": "^0.2.1",
"karma-traceur-preprocessor": "^0.2.2",
"pipe": "git://github.com/angular/pipe#remove-transitive-deps"
},
"scripts": {
"test": "karma start --single-run"
},
"author": "Vojta Jína <[email protected]>",
"license": "Apache-2.0"
}
Loading

0 comments on commit c8cf03f

Please sign in to comment.