Skip to content

Commit

Permalink
ship as npm package (final version)
Browse files Browse the repository at this point in the history
  • Loading branch information
nippur72 committed Oct 4, 2016
1 parent 9250f2e commit 2af75a6
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 246 deletions.
152 changes: 0 additions & 152 deletions dist/riot-ts.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/riot-ts.js.map

This file was deleted.

67 changes: 0 additions & 67 deletions dist/riot.d.ts

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "riot-typescript",
"version": "1.0.4",
"version": "1.0.7",
"description": "Riot for TypeScript",
"main": "./dist/riot-ts.js",
"typings": "./dist/riot-ts.d.ts",
"main": "./riot-ts.js",
"typings": "./riot-ts.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "tsc --module es6 && rollup riot-ts.js --format iife --name Riot -o riot-ts.globals.js && tsc && echo export as namespace Riot; >> riot-ts.d.ts"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion dist/riot-ts.d.ts → riot-ts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ export interface CompilerResult {
export interface Settings {
brackets: string;
}
export as namespace Riot;
export as namespace Riot;
123 changes: 123 additions & 0 deletions riot-ts.globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
(function (exports,riot) {
'use strict';

var Observable = (function () {
function Observable() {
riot.observable(this);
}
Observable.prototype.on = function (events, callback) { };
Observable.prototype.one = function (events, callback) { };
Observable.prototype.off = function (events) { };
Observable.prototype.trigger = function (eventName) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
};
return Observable;
}());
var Element = (function () {
function Element() {
}
Element.prototype.update = function (data) { };
Element.prototype.unmount = function (keepTheParent) { };
Element.prototype.on = function (eventName, fun) { };
Element.prototype.one = function (eventName, fun) { };
Element.prototype.off = function (events) { };
Element.prototype.trigger = function (eventName) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
};
Element.prototype.mixin = function (mixinObject, instance) { };
Element.createElement = function (options) {
var tagName = this.prototype.tagName;
var el = document.createElement(tagName);
riot.mount(el, tagName, options);
return el;
};
return Element;
}());
// new extend, works with getters and setters
function extend(d, element) {
var map = Object.keys(element.prototype).reduce(function (descriptors, key) {
descriptors[key] = Object.getOwnPropertyDescriptor(element.prototype, key);
return descriptors;
}, {});
Object.defineProperties(d, map);
}
/* old extend, without getters and setters
function extend(d, element) {
Object.keys(element.prototype).forEach((key) => d[key] = element.prototype[key]);
}
*/
var precompiledTags = {};
function registerClass(element) {
function registerTag(compiledTag) {
var transformFunction = function (opts) {
extend(this, element); // copies prototype into "this"
element.apply(this, [opts]); // calls class constructor applying it on "this"
if (element.prototype.mounted !== undefined)
this.on("mount", this.mounted);
if (element.prototype.unmounted !== undefined)
this.on("unmount", this.unmounted);
if (element.prototype.updating !== undefined)
this.on("update", this.updating);
if (element.prototype.updated !== undefined)
this.on("updated", this.updated);
// TODO support for init(opts) ?
};
riot.tag2(compiledTag.tagName, compiledTag.html, compiledTag.css, compiledTag.attribs, transformFunction, riot.settings.brackets);
return compiledTag.tagName;
}
function loadTemplateFromHTTP(template) {
var req = new XMLHttpRequest();
req.open("GET", template, false);
req.send();
if (req.status == 200)
return req.responseText;
else
throw req.responseText;
}
;
var compiled;
// gets string template: inlined, via http request or via precompiled cache
if (element.prototype.template !== undefined) {
var tagTemplate = element.prototype.template;
if (tagTemplate.indexOf("<") < 0) {
// tag is a file
if (precompiledTags[tagTemplate] !== undefined) {
// loads it from precompiled cache
compiled = precompiledTags[tagTemplate];
}
else {
// loads from HTTP and compile on the fly
tagTemplate = loadTemplateFromHTTP(tagTemplate);
compiled = riot.compile(tagTemplate, true, { entities: true })[0];
}
}
else {
// tag is inlined, compile on the fly
compiled = riot.compile(tagTemplate, true, { entities: true })[0];
}
element.prototype.tagName = registerTag(compiled);
}
else
throw "template property not specified";
}
// @template decorator
function template(template) {
return function (target) {
target.prototype["template"] = template;
registerClass(target);
};
}

exports.Observable = Observable;
exports.Element = Element;
exports.precompiledTags = precompiledTags;
exports.registerClass = registerClass;
exports.template = template;

}((this.Riot = this.Riot || {}),riot));
Loading

0 comments on commit 2af75a6

Please sign in to comment.