arch-stream
Advanced tools
Comparing version 0.0.34 to 0.0.35
@@ -1,2 +0,2 @@ | ||
/*! arch-stream v0.0.34 | (c) 2015, falsandtru | MIT Licence */ | ||
/*! arch-stream v0.0.35 | (c) 2015, falsandtru | MIT Licence */ | ||
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
@@ -150,4 +150,4 @@ 'use strict'; | ||
} | ||
Observable.prototype.seek_ = function (map, types) { | ||
switch (types.length) { | ||
Observable.prototype.seek_ = function (map, names) { | ||
switch (names.length) { | ||
case 0: { | ||
@@ -157,11 +157,11 @@ throw new Error('ArchStream: Observable: Cannot use empty string for event type and namespace.'); | ||
case 1: { | ||
return namespace(map, types.shift()); | ||
return namespace(map, names.shift()); | ||
} | ||
default: { | ||
return this.seek_(namespace(map, types.shift()).map, types); | ||
return this.seek_(namespace(map, names.shift()).map, names); | ||
} | ||
} | ||
return; | ||
function namespace(map, type) { | ||
return map[type] && map[type].map ? map[type] : map[type] = { | ||
function namespace(map, name) { | ||
return map[name] && map[name].map ? map[name] : map[name] = { | ||
map: Object.create(null), | ||
@@ -254,4 +254,4 @@ list: [] | ||
var map = _a.map, list = _a.list; | ||
return Object.keys(map).reduce(function (list, type) { | ||
void list.unshift.apply(list, collect(map[type])); | ||
return Object.keys(map).reduce(function (list, name) { | ||
void list.unshift.apply(list, collect(map[name])); | ||
return list; | ||
@@ -258,0 +258,0 @@ }, list.slice()); |
@@ -1,2 +0,2 @@ | ||
/*! arch-stream v0.0.34 | (c) 2015, falsandtru | MIT Licence */ | ||
/*! arch-stream v0.0.35 | (c) 2015, falsandtru | MIT Licence */ | ||
require=function t(e,r,n){function o(u,s){if(!r[u]){if(!e[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var f=r[u]={exports:{}};e[u][0].call(f.exports,function(t){var r=e[u][1][t];return o(r?r:t)},f,f.exports,t,e,r,n)}return r[u].exports}for(var i="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}({1:[function(t,e,r){"use strict";function n(t){return t}var o=t("../lib/thenable"),i=t("./tick"),u=Object.create(null),s=function(){function t(t,e){void 0===e&&(e=n),this.parent=t,this.listener=e,this.memory_=u,this.collection_=[],this.transform_=!1,this.listeners_=[],t&&(this.parent.child_=this)}return t.prototype.root=function(){return this.parent?this.parent.root():this},t.prototype.collect_=function(){if(this.collection_.length>0)return this.collection_;var t=this,e=[];do void e.push(t);while(t=t.child_);return this.collection_=e},t.prototype.transport_=function(t,e){function r(t,r,s){function c(t){return o.isThenable(t)?void t.then(c,c):(i=!0,r=s?t:r,void(u&&n.child_&&void n.child_.send(r,e)))}return t.every(function(t){n=t,n.memory_=r;var e=n.listener(n.memory_);return o.isThenable(e)?(i=!1,void e.then(c,c),i):(r=s?e:r,!0)})}var n,i=!1,u=!1,s=r(this.collect_(),t,this.transform_);u=!0,s&&"function"==typeof e&&void e(t)},t.prototype.clone=function(){function e(r){return r.parent?new t(e(r.parent),r.listener):new t(void 0,r.listener)}return e(this)},t.prototype.connect=function(t){return this.parent.child_=t,t.parent=this.parent,this},t.prototype.send=function(t,e,r){switch(!0){case"function"==typeof e:return this.send(t,!1,e);case e===!0:return void i["default"](this.transport_.bind(this,t,r)),this;case e===!1:default:return void this.transport_(t,r),this}},t.prototype.recv=function(e){var r=new t(this);return this.listener=e,this.collection_=[],this.memory_!==u&&void this.send(this.memory_),r},t.prototype.trans=function(t){return this.transform_=!0,this.recv(t)},t.prototype.then=function(e,r){var n=this,o=new t;return this.listeners_.push(o),this.trans(function(t){var e=n.listeners_;n.listeners_=[];for(var r=0;r<e.length;++r)e[r].send(t)}),o.trans(e)},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=s},{"../lib/thenable":5,"./tick":7}],2:[function(t,e,r){"use strict";function n(){}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],3:[function(t,e,r){"use strict";var n=t("./noop"),o=t("./thenable"),i=/$^/,u=function(){function t(t){void 0===t&&(t=i),this.separator_=t,this.map_=Object.create(null)}return t.prototype.seek_=function(t,e){function r(t,e){return t[e]&&t[e].map?t[e]:t[e]={map:Object.create(null),list:[]}}switch(e.length){case 0:throw new Error("ArchStream: Observable: Cannot use empty string for event type and namespace.");case 1:return r(t,e.shift());default:return this.seek_(r(t,e.shift()).map,e)}},t.prototype.on=function(t,e){return void this.seek_(this.map_,t.toString().split(this.separator_)).list.push(e),this},t.prototype.off=function(t,e){switch(typeof e){case"function":var r=this.seek_(this.map_,t.toString().split(this.separator_)).list,n=r.indexOf(e);switch(n){case-1:break;case 0:void r.shift();break;default:void r.splice(n,1)}return this;case"undefined":var o=this.seek_(this.map_,t.toString().split(this.separator_));return o.map=Object.create(null),o.list=[],this;default:throw new TypeError("ArchStream: Observable: Invalid type argument: "+e)}},t.prototype.once=function(t,e){var r=this,n=function(o){void r.off(t,n),void e(o)};return void this.on(t,n),this},t.prototype.emit=function(t,e,r){function i(t){var e=t.map,r=t.list;return Object.keys(e).reduce(function(t,r){return void t.unshift.apply(t,i(e[r])),t},r.slice())}void 0===r&&(r=n["default"]);var u,s=[],c=!!e&&"object"==typeof e;return c&&(u=e.returnValue,Object.defineProperties(e,{returnValue:{get:function(){return u}},returnValues:{get:function(){return Object.freeze(s.slice())}}})),void i(this.seek_(this.map_,t.toString().split(this.separator_))).reduce(function(t,e){return u=e(t),s.unshift(u),t},e),o.isThenable(u)?void u.then(function(t){return r(e)},function(t){return r(e)}):void r(e),this},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=u},{"./noop":2,"./thenable":5}],4:[function(t,e,r){"use strict";var n=t("../proxy/case"),o=t("../proxy/hook"),i=t("../proxy/responsibility");Object.defineProperty(r,"__esModule",{value:!0}),r["default"]={Case:n["default"],Hook:o["default"],Responsibility:i["default"]}},{"../proxy/case":8,"../proxy/hook":9,"../proxy/responsibility":10}],5:[function(t,e,r){"use strict";function n(t){return!!t&&"object"==typeof t&&void 0!==t.then}r.isThenable=n},{}],6:[function(t,e,r){"use strict";var n=function(){function t(){this.queue_=[],this.processing_=[],this.limit_=1/0,this.volume_=1/0}return t.prototype.isDrainable_=function(){return this.processing_.length<this.volume_},t.prototype.discharger_=function(t,e){},t.prototype.flow=function(t,e,r){void 0===e&&(e=1/0),void 0===r&&(r=function(){return null}),this.volume_=t,this.limit_=e,this.discharger_=r},t.prototype.enqueue=function(t){if(this.isDrainable_())return void this.processing_.push(t),void this.resolver_(t),!0;this.queue_.push(t);do void this.discharger_(this.queue_,this.processing_);while(this.processing_.length+this.queue_.length>this.limit_);return!1},t.prototype.dequeue=function(t){var e=this.processing_.indexOf(t);e>0?void this.processing_.splice(e,1):void this.processing_.shift(),this.queue_.length>0&&this.isDrainable_()&&void this.enqueue(this.queue_.shift())},t.prototype.register=function(t){this.resolver_=t},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],7:[function(t,e,r){"use strict";var n;!function(t){function e(t){void o.push(t),void n()}function r(){void--i,void n();for(var t=o.length;t-- >0;)void o.shift()()}function n(){if(0!==o.length)if(u)for(;2>i;)void Promise.resolve().then(r),void++i;else for(;i<s.length;)void setTimeout(r,s[i%s.length]),void++i}t.queue=e;var o=[],i=0,u="function"==typeof Promise,s=[0,4,10,20,25].reverse()}(n||(n={}));var o=Function("return typeof process === 'object' && typeof window !== 'object'")();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o?Function("return fn => process.nextTick(fn)")():n.queue},{}],8:[function(t,e,r){"use strict";function n(t,e){function r(){for(var t=[],r=0;r<arguments.length;r++)t[r-0]=arguments[r];return function(r){var o=+n[e(r)+""];o>-1&&o<t.length&&t[o](r)}}var n=Object.create(null);return void t.reduce(function(t,e,r){return n[e+""]=r},void 0),function(t){return{pipe:r}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],9:[function(t,e,r){"use strict";function n(t){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];return t.map(function(t){return function(e){n(e),t(e),u(e)}})}var r=t.pre,n=void 0===r?o["default"]:r,i=t.post,u=void 0===i?o["default"]:i;return function(t){return{pipe:e}}}var o=t("../lib/noop");Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{"../lib/noop":2}],10:[function(t,e,r){"use strict";function n(){function t(t,r){e.pipe=function(){for(var e=[],n=0;n<arguments.length;n++)e[n-0]=arguments[n];return e.map(function(e){return function(n){if(!(r(n)instanceof t))throw TypeError("ArchStream: ResponsibilityProxy: Uncovered internal entity: "+r(n).constructor);e(n)}})},e["export"]=function(){return function(e){r(e)instanceof t&&void Object.freeze(r(e))}}}var e;return function(r){return e={rule:t}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],11:[function(t,e,r){"use strict";var n=t("./modular"),o=function(){function t(t){this.extract_=t,this.procs_=[],this.branched_=0}return t.prototype.register=function(t){var e=this.procs_.length;return void t.reduceRight(function(t,r,n){return t[n+e]=r,t},this.procs_),this},t.prototype["import"]=function(e,r){var n=this;return void this.throwErrorIfNotImportable_(e,r),r&&(e=(new t)["import"](e)["export"]().wrap(function(t,e){return n.extract_(t)instanceof r?e(t):0})),void--e.count,e.count<0&&void e.throwCountExceededError(),void this.register(e.procs),this},t.prototype["export"]=function(t){return new n["default"](this.procs_,t,this.branched_)},t.prototype.throwErrorIfNotImportable_=function(t,e){e?((t.branched>0||this.branched_>1)&&(void--t.count,void this.throwConditionalImportError()),this.branched_=1):(t.branched>0&&this.branched_>0&&(void--t.count,void this.throwConditionalImportError()),this.branched_=t.branched>0?t.branched+1:t.branched)},t.prototype.throwConditionalImportError=function(){throw new Error("ArchStream: Conditional import cannot call from different streams.")},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o},{"./modular":12}],12:[function(t,e,r){"use strict";var n=t("../lib/throttle"),o=t("../lib/tick"),i=t("../lib/noop"),u=function(){function t(t,e,r){var n=this;void 0===e&&(e=1),this.procs=t,this.count=e,this.branched=r,void o["default"](function(t){return 0<n.count&&n.count<1/0&&n.throwCountDeprivedError()})}return t.prototype.compose_=function(){this.last_=this.procs.map(function(t){return t.clone()}).reduce(function(t,e){return t.connect(e.root())&&e}),this.first_=this.last_.root()},t.prototype.wrap=function(t){function e(e){return function(r){return t(r,e)}}void this.compose_();var r=this.last_;do r=r.parent,r.listener=e(r.listener);while(r.parent);return this.procs=[this.last_],this},t.prototype.read_=function(t){void--this.count,this.count<0&&void this.throwCountExceededError(),void this.compose_(),void this.last_.recv(t)},t.prototype.read=function(t){var e=this;void 0===t&&(t=i["default"]);var r=!1;return void this.read_(function(n){e.flow_&&void o["default"](function(){return void e.flow_.dequeue(n)}),r&&void t(n)}),r=!0,this},t.prototype.write_=function(t,e){void this.first_.send(t,e)},t.prototype.write=function(t,e){return this.flow_?void this.flow_.enqueue(t):void this.write_(t,e),this},t.prototype.flow=function(t,e,r){var o=this;return void 0===e&&(e=1/0),this.flow_=new n["default"],void this.flow_.flow(t,e,r),void this.flow_.register(function(t){return o.write_(t)}),this},t.prototype.throwCountExceededError=function(){throw new Error("ArchStream: Import and read counts are exeeded.")},t.prototype.throwCountDeprivedError=function(){throw this.count=0,new Error("ArchStream: Import and read counts are not deprived.")},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=u},{"../lib/noop":2,"../lib/throttle":6,"../lib/tick":7}],13:[function(t,e,r){"use strict";var n=t("../lib/message"),o=t("./compose"),i=t("./modular"),u=function(){function t(t,e){var r=this;void 0===e&&(e=new n["default"]),this.parent_=t,this.message_=e,this.proxies_=[],this.parent_&&void this.parent_.proxies_.reduce(function(t,e){return r.proxy(e)},void 0)}return t.prototype.pipe=function(e){return new t(this,this.message_.recv(e))},t.prototype["import"]=function(t,e){return t instanceof i["default"]?(new o["default"])["import"](t,e):new o["default"](t)},t.prototype["export"]=function(t){return(new o["default"]).register([this.message_])["export"](t)},t.prototype.proxy=function(e){function r(e,n,o){function i(t){return Array.isArray(t)?t:[t]}var u=e.proxies_.filter(function(t){return"function"==typeof t[n]}).reduce(function(t,e){return i(e[n].apply(void 0,t)||t)},o),s="pipe";switch(n){case s:return t.prototype[n].call(e,u[0]);case"import":throw new Error("ArchStream: `import` method cannot extend by proxy.");case"export":return(c=t.prototype[n]).call.apply(c,[r(e,s,u)].concat(o));default:return r(e,s,u)}var c}var n=this,o="function"==typeof e?e():e;return this.proxies_.push(o),void Object.keys(o).filter(function(t){return t.length>0&&"_"!==t[0]&&"_"!==t[t.length-1]}).filter(function(t){return"function"==typeof o[t]}).reduce(function(t,e){return n[e]=function(){for(var t=[],o=0;o<arguments.length;o++)t[o-0]=arguments[o];return r(n,e,t)}},void 0),this},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=u},{"../lib/message":1,"./compose":11,"./modular":12}],"arch-stream":[function(t,e,r){"use strict";function n(){return new i["default"]}function o(){return new u["default"]}var i=t("./stream/transform");r.ArchStream=i["default"];var u=t("./lib/message");r.Message=u["default"];var s=t("./lib/proxy");r.Proxy=s["default"];var c=t("./lib/tick");r.Tick=c["default"];var a=t("./lib/observable");r.Observable=a["default"],Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n;var n,f={Msg:o,Proxy:s["default"],Tick:c["default"]};!function(t){t.Msg=f.Msg,t.Proxy=f.Proxy,t.Tick=f.Tick}(n||(n={})),r.Msg=o},{"./lib/message":1,"./lib/observable":3,"./lib/proxy":4,"./lib/tick":7,"./stream/transform":13}]},{},["arch-stream",1,2,3,4,5,6,7,8,9,10,11,12,13]),"object"==typeof module&&module&&"exports"in module&&(module.exports=require("arch-stream")); |
{ | ||
"name": "arch-stream", | ||
"version": "0.0.34", | ||
"version": "0.0.35", | ||
"description": "Pipeline stream for software architecture of Domain-Driven Design and Data-Oriented Design.", | ||
@@ -5,0 +5,0 @@ "private": false, |
interface String { | ||
split(separator: string|RegExp, limit?: number): string[]; | ||
split(separator: string | RegExp, limit?: number): string[]; | ||
} | ||
interface Array<T> { | ||
split(separator: string|RegExp, limit?: number): T[]; | ||
split(separator: string | RegExp, limit?: number): T[]; | ||
} |
@@ -24,3 +24,3 @@ import Message from './message'; | ||
sender | ||
.send({val: 0}); | ||
.send({ val: 0 }); | ||
sender | ||
@@ -35,3 +35,3 @@ .recv(e => assert(e.val === 0) || done()); | ||
sender | ||
.send({val: 0}); | ||
.send({ val: 0 }); | ||
}); | ||
@@ -42,3 +42,3 @@ | ||
new Message<Entity<number>>() | ||
.send({val: 0}, true) | ||
.send({ val: 0 }, true) | ||
.recv(e => { | ||
@@ -54,5 +54,5 @@ assert(async === true); | ||
new Message<Entity<number>>() | ||
.send({val: 0}, e => assert(e.val === 0 && ++cnt === 1)) | ||
.send({val: 1}, e => assert(e.val === 1 && ++cnt === 2)) | ||
.send({val: 0}, _ => done()); | ||
.send({ val: 0 }, e => assert(e.val === 0 && ++cnt === 1)) | ||
.send({ val: 1 }, e => assert(e.val === 1 && ++cnt === 2)) | ||
.send({ val: 0 }, _ => done()); | ||
}); | ||
@@ -64,7 +64,7 @@ | ||
new Message<Entity<number>>() | ||
.send({val: 0}, true, e => assert(e.val === 0 && ++cnt === 3 && async === true)) | ||
.send({val: 1}, e => assert(e.val === 1 && ++cnt === 1 && async === false)) | ||
.send({val: 2}, true, e => assert(e.val === 2 && ++cnt === 4 && async === true)) | ||
.send({val: 3}, e => assert(e.val === 3 && ++cnt === 2 && async === false)) | ||
.send({val: 0}, true, _ => done()); | ||
.send({ val: 0 }, true, e => assert(e.val === 0 && ++cnt === 3 && async === true)) | ||
.send({ val: 1 }, e => assert(e.val === 1 && ++cnt === 1 && async === false)) | ||
.send({ val: 2 }, true, e => assert(e.val === 2 && ++cnt === 4 && async === true)) | ||
.send({ val: 3 }, e => assert(e.val === 3 && ++cnt === 2 && async === false)) | ||
.send({ val: 0 }, true, _ => done()); | ||
async = true; | ||
@@ -87,3 +87,3 @@ }); | ||
msg | ||
.send({val: 0}) | ||
.send({ val: 0 }) | ||
.recv(e => { | ||
@@ -100,3 +100,3 @@ const msg = new Message<number>(); | ||
msg | ||
.send({val: 0}); | ||
.send({ val: 0 }); | ||
}); | ||
@@ -103,0 +103,0 @@ |
@@ -63,3 +63,3 @@ import {Message as IMessage} from 'arch-stream'; | ||
msg.memory_ = <T>data; | ||
const result: T|PromiseLike<T> = msg.listener(msg.memory_); | ||
const result: T | PromiseLike<T> = msg.listener(msg.memory_); | ||
@@ -78,3 +78,3 @@ if (!isThenable(result)) { | ||
function resume(result: T|PromiseLike<T>): void { | ||
function resume(result: T | PromiseLike<T>): void { | ||
if (isThenable(result)) return void result.then(resume, resume); | ||
@@ -144,3 +144,3 @@ called = true; | ||
private transform_ = false; | ||
public trans<U>(callback: (data: T) => U|PromiseLike<U>): Message<U> { | ||
public trans<U>(callback: (data: T) => U | PromiseLike<U>): Message<U> { | ||
this.transform_ = true; | ||
@@ -151,3 +151,3 @@ return <any>this.recv(callback); | ||
private listeners_: Message<T>[] = []; | ||
public then<U>(done: (data: T) => U|PromiseLike<U>, _?: ICallback<any>): PromiseLike<U> { | ||
public then<U>(done: (data: T) => U | PromiseLike<U>, _?: ICallback<any>): PromiseLike<U> { | ||
const msg = new Message<T>(); | ||
@@ -154,0 +154,0 @@ this.listeners_.push(msg); |
@@ -10,5 +10,5 @@ var noop_1 = require('./noop'); | ||
} | ||
Observable.prototype.seek_ = function (map, types) { | ||
assert(types.length > 0); | ||
switch (types.length) { | ||
Observable.prototype.seek_ = function (map, names) { | ||
assert(names.length > 0); | ||
switch (names.length) { | ||
case 0: { | ||
@@ -18,6 +18,6 @@ throw new Error("ArchStream: Observable: Cannot use empty string for event type and namespace."); | ||
case 1: { | ||
return namespace(map, types.shift()); | ||
return namespace(map, names.shift()); | ||
} | ||
default: { | ||
return this.seek_(namespace(map, types.shift()).map, types); | ||
return this.seek_(namespace(map, names.shift()).map, names); | ||
} | ||
@@ -27,6 +27,6 @@ } | ||
return; | ||
function namespace(map, type) { | ||
return map[type] && map[type].map | ||
? map[type] | ||
: map[type] = { | ||
function namespace(map, name) { | ||
return map[name] && map[name].map | ||
? map[name] | ||
: map[name] = { | ||
map: Object.create(null), | ||
@@ -115,4 +115,4 @@ list: [] | ||
return Object.keys(map) | ||
.reduce(function (list, type) { | ||
void list.unshift.apply(list, collect(map[type])); | ||
.reduce(function (list, name) { | ||
void list.unshift.apply(list, collect(map[name])); | ||
return list; | ||
@@ -119,0 +119,0 @@ }, list.slice()); |
@@ -83,13 +83,13 @@ import Observable from './observable'; | ||
let cnt = 0; | ||
new Observable<string, {val: number, returnValue: number}>() | ||
new Observable<string, { val: number, returnValue: number }>() | ||
.on('test', data => data.val + 1) | ||
.on('test', data => data.returnValue + 1) | ||
.on('test', data => assert(data.val === 0 && data.returnValue === 2 && ++cnt === 1)) | ||
.emit('test', {val: 0, returnValue: 0}) | ||
.emit('test', { val: 0, returnValue: 0 }) | ||
.off('test') | ||
.emit('test', { val: 0, returnValue: void 0}, data => assert(data.returnValue === void 0 && ++cnt === 2) || done()); | ||
.emit('test', { val: 0, returnValue: void 0 }, data => assert(data.returnValue === void 0 && ++cnt === 2) || done()); | ||
}); | ||
it('returnValue thenable', function (done) { | ||
new Observable<string, {val: number, returnValue: PromiseLike<number>}>() | ||
new Observable<string, { val: number, returnValue: PromiseLike<number> }>() | ||
.on('test', data => data.returnValue.then(v => new Message<number>().send(<any>assert(++data.val === 1) || ++v, true))) | ||
@@ -103,9 +103,9 @@ .on('test', data => data.returnValue.then(v => new Message<number>().send(<any>assert(++data.val === 3) || ++v, true))) | ||
let cnt = 0; | ||
new Observable<string, {val: number, returnValues: number[]}>() | ||
new Observable<string, { val: number, returnValues: number[] }>() | ||
.on('test', data => data.val + 1) | ||
.on('test', data => data.val + 2) | ||
.on('test', data => assert.deepEqual(data.returnValues, [2, 1]) || assert(++cnt === 1)) | ||
.emit('test', {val: 0, returnValues: [0]}) | ||
.emit('test', { val: 0, returnValues: [0] }) | ||
.off('test') | ||
.emit('test', { val: 0, returnValues: void 0}, data => assert(data.returnValues.length === 0 && ++cnt === 2) || done()); | ||
.emit('test', { val: 0, returnValues: void 0 }, data => assert(data.returnValues.length === 0 && ++cnt === 2) || done()); | ||
}); | ||
@@ -112,0 +112,0 @@ |
@@ -17,9 +17,9 @@ import noop from './noop'; | ||
export default class Observable<T extends string|number, E extends { returnValue?: any; returnValues?: any[] }> { | ||
constructor(private separator_: string|RegExp = RegNothing) { | ||
export default class Observable<T extends string | number, E extends { returnValue?: any; returnValues?: any[] }> { | ||
constructor(private separator_: string | RegExp = RegNothing) { | ||
} | ||
private map_: ListenerMap<E> = Object.create(null); | ||
private seek_(map: ListenerMap<E>, types: string[]): ListenerSet<E> { | ||
assert(types.length > 0); | ||
switch (types.length) { | ||
private seek_(map: ListenerMap<E>, names: string[]): ListenerSet<E> { | ||
assert(names.length > 0); | ||
switch (names.length) { | ||
case 0: { | ||
@@ -29,6 +29,6 @@ throw new Error(`ArchStream: Observable: Cannot use empty string for event type and namespace.`); | ||
case 1: { | ||
return namespace(map, types.shift()); | ||
return namespace(map, names.shift()); | ||
} | ||
default: { | ||
return this.seek_(namespace(map, types.shift()).map, types); | ||
return this.seek_(namespace(map, names.shift()).map, names); | ||
} | ||
@@ -39,9 +39,9 @@ } | ||
function namespace(map: ListenerMap<E>, type: string): ListenerSet<E> { | ||
return map[type] && map[type].map | ||
? map[type] | ||
: map[type] = { | ||
map: <ListenerMap<E>>Object.create(null), | ||
list: <Listener<E>[]>[] | ||
}; | ||
function namespace(map: ListenerMap<E>, name: string): ListenerSet<E> { | ||
return map[name] && map[name].map | ||
? map[name] | ||
: map[name] = { | ||
map: <ListenerMap<E>>Object.create(null), | ||
list: <Listener<E>[]>[] | ||
}; | ||
} | ||
@@ -126,4 +126,4 @@ } | ||
return Object.keys(map) | ||
.reduce((list, type) => { | ||
void list.unshift(...collect(map[type])); | ||
.reduce((list, name) => { | ||
void list.unshift(...collect(map[name])); | ||
return list; | ||
@@ -130,0 +130,0 @@ }, list.slice()); |
@@ -9,3 +9,3 @@ export default class Throttle<T> { | ||
} | ||
private discharger_(queue: T[], processing: T[]): T[]|void { | ||
private discharger_(queue: T[], processing: T[]): T[] | void { | ||
return; | ||
@@ -12,0 +12,0 @@ } |
import {ICallback, ITransformStream} from 'arch-stream'; | ||
interface CaseProxy<T, U> { | ||
pipe(...callbacks: ICallback<T>[]): U&CaseProxy<T, U>&ITransformStream<T, U&CaseProxy<T, U>>; | ||
pipe(...callbacks: ICallback<T>[]): U & CaseProxy<T, U> & ITransformStream<T, U & CaseProxy<T, U>>; | ||
} | ||
export default function <T, U extends number|string>(index: U[], indexer: (entity: T) => U) { | ||
export default function <T, U extends number | string>(index: U[], indexer: (entity: T) => U) { | ||
const map: { [index: string]: number; } = Object.create(null); | ||
@@ -15,3 +15,3 @@ void index | ||
function pipe(...args: ICallback<T>[]): ICallback<T>|ICallback<T>[]|CaseProxy<T, {}>&ITransformStream<T, {}&CaseProxy<T, {}>> { | ||
function pipe(...args: ICallback<T>[]): ICallback<T> | ICallback<T>[] | CaseProxy<T, {}> & ITransformStream<T, {} & CaseProxy<T, {}>> { | ||
return (entity: T) => { | ||
@@ -18,0 +18,0 @@ const i = +map[indexer(entity) + '']; |
@@ -12,3 +12,3 @@ import {ICallback, ITransformStream} from 'arch-stream'; | ||
function pipe(...args: ICallback<T>[]): ICallback<T>|ICallback<T>[]|ITransformStream<T, {}> { | ||
function pipe(...args: ICallback<T>[]): ICallback<T> | ICallback<T>[] | ITransformStream<T, {}> { | ||
return args | ||
@@ -15,0 +15,0 @@ .map(proc => (entity: T) => { |
import {ICallback, ITransformStream} from 'arch-stream'; | ||
interface ResponsibilityProxy<T, U> { | ||
rule<V>(LocalEntity: new (..._) => V, extract: (entity: T) => V): U&ITransformStream<T, U>; | ||
rule<V>(LocalEntity: new (..._) => V, extract: (entity: T) => V): U & ITransformStream<T, U>; | ||
} | ||
@@ -6,0 +6,0 @@ |
@@ -7,3 +7,3 @@ import {ArchStream as IArchStream, ITransformStream, ICallback} from 'arch-stream'; | ||
interface IProxy<T> { | ||
[method: string]: (...args: ICallback<T>[]) => void|ICallback<T>|ICallback<T>[]; | ||
[method: string]: (...args: ICallback<T>[]) => void | ICallback<T> | ICallback<T>[]; | ||
} | ||
@@ -28,3 +28,3 @@ | ||
public import<V>(module: ModularStream<T>, MethodEntity?: new (..._) => V): ComposeStream<T> | ||
public import<V>(pm: ModularStream<T>|((entity: T) => V), MethodEntity?: new (..._) => V): ComposeStream<T> { | ||
public import<V>(pm: ModularStream<T> | ((entity: T) => V), MethodEntity?: new (..._) => V): ComposeStream<T> { | ||
return pm instanceof ModularStream | ||
@@ -41,3 +41,3 @@ ? new ComposeStream<T>().import(pm, MethodEntity) | ||
private proxies_: IProxy<T>[] = []; | ||
public proxy<S extends IProxy<T>>(gen: S|((shadow?: ITransformStream<T, {}>) => S)): S&this { | ||
public proxy<S extends IProxy<T>>(gen: S | ((shadow?: ITransformStream<T, {}>) => S)): S & this { | ||
const proxy = typeof gen === 'function' ? (<() => S>gen)() : <S>gen; | ||
@@ -49,3 +49,3 @@ this.proxies_.push(proxy); | ||
.reduce((_, method) => this[method] = (...args: any[]) => compose<S>(this, method, args), void 0); | ||
return <S&this>this; | ||
return <S & this>this; | ||
@@ -52,0 +52,0 @@ function compose<S>(self: ArchStream<T>, method: string, args: ICallback<T>[]): ArchStream<T> & S { |
@@ -22,6 +22,6 @@ import A, {Proxy} from 'arch-stream'; | ||
.export() | ||
.read(e => assert.deepEqual(e, {state: 20}) || done()) | ||
.read(e => assert.deepEqual(e, { state: 20 }) || done()) | ||
.write(new Entity()); | ||
}); | ||
it('imported case', function (done) { | ||
@@ -38,8 +38,8 @@ const mdl = A<Entity>() | ||
.export() | ||
.read(e => assert.deepEqual(e, {state: 20}) || done()) | ||
.read(e => assert.deepEqual(e, { state: 20 }) || done()) | ||
.write(new Entity()); | ||
}); | ||
}); | ||
}); |
@@ -23,5 +23,5 @@ import A, {Proxy} from 'arch-stream'; | ||
}); | ||
}); | ||
}); |
@@ -19,3 +19,3 @@ import A, {Proxy} from 'arch-stream'; | ||
}); | ||
it('mismatch', function (done) { | ||
@@ -36,3 +36,3 @@ try { | ||
}); | ||
it('freeze', function (done) { | ||
@@ -67,5 +67,5 @@ 'use strict'; | ||
}); | ||
}); | ||
}); |
@@ -25,7 +25,7 @@ import A, {Proxy} from 'arch-stream'; | ||
}); | ||
it('mismatch', function (done) { | ||
try { | ||
A<Entity>() | ||
.proxy(Proxy.Case<Entity, State>([State.pending, State.resolved, State.rejected], entity => entity.state)) | ||
.proxy(Proxy.Case<Entity, State>([State.pending, State.resolved, State.rejected], entity => entity.state)) | ||
.proxy(Proxy.Responsibility<Entity>()) | ||
@@ -37,3 +37,3 @@ .rule(Entity, e => e) | ||
.read(e => assert(e.state === State.pending) || done()) | ||
.write(<Entity>{state: State.pending}); | ||
.write(<Entity>{ state: State.pending }); | ||
} | ||
@@ -45,5 +45,5 @@ catch (err) { | ||
}); | ||
}); | ||
}); |
@@ -15,3 +15,3 @@ import A, {Msg, Tick} from 'arch-stream'; | ||
.read(e => assert(e.val === 0) || done()) | ||
.write({val: 0}); | ||
.write({ val: 0 }); | ||
}); | ||
@@ -24,3 +24,3 @@ | ||
.read(e => assert(e.val === 1) || done()) | ||
.write({val: 0}); | ||
.write({ val: 0 }); | ||
}); | ||
@@ -34,3 +34,3 @@ | ||
.read(e => assert(e.val === 2) || done()) | ||
.write({val: 0}); | ||
.write({ val: 0 }); | ||
}); | ||
@@ -47,5 +47,5 @@ | ||
.read() | ||
.write({val: 0}, e => assert(e.val === 4 && ++cnt === 1)) | ||
.write({val: 1}, e => assert(e.val === 5 && ++cnt === 2)) | ||
.write({val: 0}, _ => assert(++cnt === 3) || done()); | ||
.write({ val: 0 }, e => assert(e.val === 4 && ++cnt === 1)) | ||
.write({ val: 1 }, e => assert(e.val === 5 && ++cnt === 2)) | ||
.write({ val: 0 }, _ => assert(++cnt === 3) || done()); | ||
}); | ||
@@ -71,3 +71,3 @@ | ||
stm.write({val: 0}); | ||
stm.write({ val: 0 }); | ||
}); | ||
@@ -95,3 +95,3 @@ | ||
stm | ||
.write({val: 0}); | ||
.write({ val: 0 }); | ||
}); | ||
@@ -161,3 +161,3 @@ | ||
.read(e => assert(e.val === 15) || done()) | ||
.write({val: 0}); | ||
.write({ val: 0 }); | ||
}); | ||
@@ -277,3 +277,3 @@ | ||
} | ||
A<Entity<Array<void>|Date|RegExp>>() | ||
A<Entity<Array<void> | Date | RegExp>>() | ||
.import(e => e.req) | ||
@@ -342,4 +342,4 @@ .import(A<Entity<Array<void>>>().pipe(e => e.res += 1).export(), Array) | ||
.read(e => assert(e.val === 2 && async === false || e.val === 3 && async === true) || e.val === 3 && done()) | ||
.write({val: 1}) | ||
.write({val: 2}); | ||
.write({ val: 1 }) | ||
.write({ val: 2 }); | ||
async = true; | ||
@@ -346,0 +346,0 @@ }); |
@@ -1,3 +0,1 @@ | ||
import {} from 'arch-stream'; | ||
describe('Issue: GitHub', function () { | ||
@@ -4,0 +2,0 @@ describe('#', function () { |
@@ -24,3 +24,3 @@ /** | ||
export class ArchStream<T> implements Transform<T, ITransformStream<T, {}>>, Importable<T, IComposeStream<T, void>, void> { | ||
proxy<U extends IProxy<T, {}, {}>>(proxy: (shadow?: ITransformStream<T, {}>) => U): U&ITransformStream<T, U>; | ||
proxy<U extends IProxy<T, {}, {}>>(proxy: (shadow?: ITransformStream<T, {}>) => U): U & ITransformStream<T, U>; | ||
pipe(callback: ICallback<T>): ITransformStream<T, {}>; | ||
@@ -31,7 +31,7 @@ import(module: IModularStream<T>): IComposeStream<T, void>; | ||
export interface ICallback<T> { | ||
(entity: T): PromiseLike<T>|any; | ||
(entity: T): PromiseLike<T> | any; | ||
} | ||
export interface ITransformStream<T, U extends {}> extends Transform<T, ITransformStream<T, {}>>, Exportable<T, IModularStream<T>> { | ||
proxy<V extends IProxy<T, U, {}>>(proxy: (shadow: ITransformStream<T, U>) => V): U&V&ITransformStream<T, U&V>; | ||
pipe(callback: ICallback<T>): U&ITransformStream<T, U>; | ||
proxy<V extends IProxy<T, U, {}>>(proxy: (shadow: ITransformStream<T, U>) => V): U & V & ITransformStream<T, U & V>; | ||
pipe(callback: ICallback<T>): U & ITransformStream<T, U>; | ||
} | ||
@@ -73,8 +73,8 @@ export interface IComposeStream<T, U> extends Importable<T, IComposeStream<T, U>, U>, Exportable<T, IModularStream<T>> { | ||
recv(callback: ICallback<T>): Message<T>; | ||
trans<U>(callback: (data: T) => U|PromiseLike<U>): Message<U>; | ||
then<U>(done: (data: T) => U|PromiseLike<U>, _?: ICallback<any>): PromiseLike<U> | ||
trans<U>(callback: (data: T) => U | PromiseLike<U>): Message<U>; | ||
then<U>(done: (data: T) => U | PromiseLike<U>, _?: ICallback<any>): PromiseLike<U> | ||
} | ||
export const Proxy: { | ||
Case<T, U extends number|string>(index: U[], indexer: (entity: T) => U): <U>(shadow?: ITransformStream<T, U>) => CaseProxy<T, U>; | ||
Case<T, U extends number | string>(index: U[], indexer: (entity: T) => U): <U>(shadow?: ITransformStream<T, U>) => CaseProxy<T, U>; | ||
Hook<T>(hooks: { pre?: ICallback<T>, post?: ICallback<T> }): <U>(shadow?: ITransformStream<T, U>) => HookProxy<T, U>; | ||
@@ -85,6 +85,6 @@ Responsibility<T>(): <U>(shadow?: ITransformStream<T, U>) => ResponsibilityProxy<T, U>; | ||
interface IProxy<T, U, V> { | ||
[method: string]: (...args) => U&V&ITransformStream<T, U&V>; | ||
[method: string]: (...args) => U & V & ITransformStream<T, U & V>; | ||
} | ||
interface CaseProxy<T, U> extends IProxy<T, U, CaseProxy<T, U>> { | ||
pipe(...callbacks: ICallback<T>[]): U&CaseProxy<T, U>&ITransformStream<T, U&CaseProxy<T, U>>; | ||
pipe(...callbacks: ICallback<T>[]): U & CaseProxy<T, U> & ITransformStream<T, U & CaseProxy<T, U>>; | ||
} | ||
@@ -94,3 +94,3 @@ interface HookProxy<T, U> extends IProxy<T, U, {}> { | ||
interface ResponsibilityProxy<T, U> extends IProxy<T, U, {}> { | ||
rule<V>(LocalEntity: new (..._) => V, extract: (entity: T) => V): U&ITransformStream<T, U>; | ||
rule<V>(LocalEntity: new (..._) => V, extract: (entity: T) => V): U & ITransformStream<T, U>; | ||
} | ||
@@ -101,3 +101,3 @@ | ||
export class Observable<T extends string|number, E> { | ||
export class Observable<T extends string | number, E> { | ||
on(type: T, listener: Listener<E>): Observable<T, E> | ||
@@ -104,0 +104,0 @@ off(type: T, listener?: Listener<E>): Observable<T, E> |
176429
4116