Skip to content

Commit c8cf03f

Browse files
committed
refactor: move rtts-assert into modules directory
The rtts assertion lib is only needed for js, but it should be treated like any other module (e.g. facade, …)
1 parent c3b442e commit c8cf03f

File tree

9 files changed

+789
-10
lines changed

9 files changed

+789
-10
lines changed

gulpfile.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var js2es5Options = {
2020
types: true, // parse types
2121
script: false, // parse as a module
2222
modules: 'register',
23-
typeAssertionModule: 'assert',
23+
typeAssertionModule: 'rtts_assert/rtts_assert',
2424
typeAssertions: true
2525
};
2626

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

5353
function createJsRuntimeTask(isWatch) {
5454
var srcFn = isWatch ? watch : gulp.src.bind(gulp);
55-
var rttsAssert = srcFn('tools/rtts-assert/src/assert.js')
56-
.pipe(gulpTraceur(js2es5Options, resolveModuleName))
57-
.pipe(gulp.dest('build/js'));
5855
var traceurRuntime = srcFn(gulpTraceur.RUNTIME_PATH)
5956
.pipe(gulp.dest('build/js'));
60-
return mergeStreams(rttsAssert, traceurRuntime);
57+
return traceurRuntime;
6158
}
6259

6360
// -----------------------

karma-js.conf.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ module.exports = function(config) {
2626
script: false,
2727
modules: 'register',
2828
types: true,
29-
// TODO: turn this on!
30-
// typeAssertions: true,
31-
// typeAssertionModule: 'assert',
29+
typeAssertions: true,
30+
typeAssertionModule: 'rtts_assert/rtts_assert',
3231
annotations: true
3332
},
3433
resolveModuleName: function(fileName) {

modules/core/src/view/view.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class View {
2121

2222
onRecordChange(record:Record, target) {
2323
// dispatch to element injector or text nodes based on context
24-
if (target is ElementInjectorTarge) {
24+
if (target instanceof ElementInjectorTarge) {
2525
// we know that it is ElementInjectorTarge
2626
var eTarget:ElementInjectorTarget = target;
2727
onChangeDispatcher.notify(this, eTarget);

modules/rtts_assert/API.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Asserting APIs:
2+
// - generated by Traceur (based on type annotations)
3+
// - can be also used in tests for instance
4+
assert.type(something, Type);
5+
assert.returnType(returnValue, Type);
6+
assert.argumentTypes(firstArg, Type, secondArg, Type);
7+
8+
// this can be used anywhere in the code
9+
// (useful inside test, when we don't wanna define an interface)
10+
assert(value).is(...)
11+
12+
13+
// Custom type assert:
14+
// - i have a custom type
15+
// - adding an assert methos
16+
assert.define(MyUser, function(value) {
17+
assert(value).is(Type, Type2); // or
18+
assert(value, 'name').is(assert.string);
19+
assert(value, 'contact').is(assert.structure({
20+
email: assert.string,
21+
cell: assert.string
22+
}));
23+
assert(value, 'contacts').is(assert.arrayOf(assert.structure({email: assert.string})));
24+
});
25+
26+
27+
28+
// Define interface (an empty type with assert method)
29+
// - returns an empty class with assert method
30+
var Email = assert.define('IEmail', function(value) {
31+
assert(value).is(String);
32+
33+
if (value.indexOf('@') !== -1) {
34+
assert.fail('has to contain "@"');
35+
}
36+
});
37+
38+
39+
// Predefined types
40+
assert.string
41+
assert.number
42+
assert.boolean
43+
assert.arrayOf(...types)
44+
assert.structure(object)

modules/rtts_assert/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://angular.github.io/assert/

modules/rtts_assert/package.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "rtts-assert",
3+
"version": "0.0.1",
4+
"description": "A type assertion library for Traceur.",
5+
"main": "./dist/cjs/assert.js",
6+
"homepage": "https://github.com/angular/assert",
7+
"repository": {
8+
"type": "git",
9+
"url": "git://github.com/angular/assert.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/angular/assert/issues"
13+
},
14+
"dependencies": {},
15+
"devDependencies": {
16+
"gulp": "^3.5.6",
17+
"gulp-connect": "~1.0.5",
18+
"gulp-traceur": "~0.4.0",
19+
"karma": "^0.12.1",
20+
"karma-chrome-launcher": "^0.1.2",
21+
"karma-jasmine": "^0.2.2",
22+
"karma-requirejs": "^0.2.1",
23+
"karma-traceur-preprocessor": "^0.2.2",
24+
"pipe": "git://github.com/angular/pipe#remove-transitive-deps"
25+
},
26+
"scripts": {
27+
"test": "karma start --single-run"
28+
},
29+
"author": "Vojta Jína <vojta.jina@gmail.com>",
30+
"license": "Apache-2.0"
31+
}

0 commit comments

Comments
 (0)