@thi.ng/api
Advanced tools
Comparing version 2.0.4 to 2.1.0
10
api.d.ts
@@ -120,3 +120,3 @@ /** | ||
enable(opts?: any): any; | ||
toggle?(): any; | ||
toggle?(): boolean; | ||
} | ||
@@ -157,5 +157,5 @@ export interface IEquiv { | ||
export interface INotify { | ||
addListener(id: string, fn: Listener, scope?: any): any; | ||
removeListener(id: string, fn: Listener, scope?: any): any; | ||
notify(event: Event): any; | ||
addListener(id: string, fn: Listener, scope?: any): boolean; | ||
removeListener(id: string, fn: Listener, scope?: any): boolean; | ||
notify(event: Event): void; | ||
} | ||
@@ -267,3 +267,3 @@ /** | ||
removeWatch(id: string): boolean; | ||
notifyWatches(oldState: T, newState: T): any; | ||
notifyWatches(oldState: T, newState: T): void; | ||
} |
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="2.1.0"></a> | ||
# [2.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/api@2.0.4...@thi.ng/api@2.1.0) (2018-03-21) | ||
### Features | ||
* **api:** add error types & ctor fns ([4d3785f](https://github.com/thi-ng/umbrella/commit/4d3785f)) | ||
<a name="2.0.4"></a> | ||
@@ -8,0 +19,0 @@ ## [2.0.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/api@2.0.3...@thi.ng/api@2.0.4) (2018-03-08) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const error_1 = require("../error"); | ||
/** | ||
@@ -16,3 +17,3 @@ * Method property decorator factory. Augments original method with | ||
if (typeof fn !== "function") { | ||
throw new Error(`${signature} is not a function`); | ||
error_1.illegalArgs(`${signature} is not a function`); | ||
} | ||
@@ -19,0 +20,0 @@ descriptor.value = function () { |
@@ -5,3 +5,4 @@ import * as decorators from "./decorators"; | ||
export * from "./compare"; | ||
export * from "./error"; | ||
export * from "./equiv"; | ||
export { decorators, mixins }; |
@@ -12,2 +12,3 @@ "use strict"; | ||
__export(require("./compare")); | ||
__export(require("./error")); | ||
__export(require("./equiv")); |
/** | ||
* Mixin class decorator, injects IEnable default implementation, | ||
* incl. a `_enabled` property. If the target also implements the | ||
* `INotify` interface, `enable()` and `disable()` will automatically | ||
* the respective emit events. | ||
* Mixin class decorator, injects IEnable default implementation, incl. | ||
* a `_enabled` property. If the target also implements the `INotify` | ||
* interface, `enable()` and `disable()` will automatically emit the | ||
* respective events. | ||
*/ | ||
export declare const IEnable: (clazz: any) => any; |
@@ -6,8 +6,7 @@ "use strict"; | ||
/** | ||
* Mixin class decorator, injects IEnable default implementation, | ||
* incl. a `_enabled` property. If the target also implements the | ||
* `INotify` interface, `enable()` and `disable()` will automatically | ||
* the respective emit events. | ||
* Mixin class decorator, injects IEnable default implementation, incl. | ||
* a `_enabled` property. If the target also implements the `INotify` | ||
* interface, `enable()` and `disable()` will automatically emit the | ||
* respective events. | ||
*/ | ||
// tslint:disable-next-line | ||
exports.IEnable = mixin_1.mixin({ | ||
@@ -32,3 +31,4 @@ _enabled: true, | ||
this._enabled ? this.disable() : this.enable(); | ||
}, | ||
return this._enabled; | ||
} | ||
}); |
import * as api from "../api"; | ||
export declare function inotify_dispatch(listeners: any[][], e: api.Event): void; | ||
/** | ||
* Mixin class decorator, injects INotify default implementation, | ||
* incl. a lazily instantiated `_listeners` property object, storing | ||
* registered listeners in ES6 sets (one set per event type). | ||
* Mixin class decorator, injects INotify default implementation, incl. | ||
* a lazily instantiated `_listeners` property object, storing | ||
* registered listeners. | ||
*/ | ||
export declare const INotify: (clazz: any) => any; |
@@ -6,10 +6,11 @@ "use strict"; | ||
function inotify_dispatch(listeners, e) { | ||
if (listeners) { | ||
const n = listeners.length; | ||
for (let i = 0; i < n; i++) { | ||
const l = listeners[i]; | ||
l[0].call(l[1], e); | ||
if (e.canceled) { | ||
return; | ||
} | ||
if (!listeners) | ||
return; | ||
const n = listeners.length; | ||
let i = 0, l; | ||
for (i = 0; i < n; i++) { | ||
l = listeners[i]; | ||
l[0].call(l[1], e); | ||
if (e.canceled) { | ||
return; | ||
} | ||
@@ -20,11 +21,9 @@ } | ||
/** | ||
* Mixin class decorator, injects INotify default implementation, | ||
* incl. a lazily instantiated `_listeners` property object, storing | ||
* registered listeners in ES6 sets (one set per event type). | ||
* Mixin class decorator, injects INotify default implementation, incl. | ||
* a lazily instantiated `_listeners` property object, storing | ||
* registered listeners. | ||
*/ | ||
// tslint:disable-next-line | ||
exports.INotify = mixin_1.mixin({ | ||
addListener(id, fn, scope) { | ||
this._listeners = this._listeners || {}; | ||
let l = this._listeners[id]; | ||
let l = (this._listeners = this._listeners || {})[id]; | ||
if (!l) { | ||
@@ -35,23 +34,23 @@ l = this._listeners[id] = []; | ||
l.push([fn, scope]); | ||
return true; | ||
} | ||
return false; | ||
}, | ||
removeListener(id, fn, scope) { | ||
this._listeners = this._listeners || {}; | ||
if (!this._listeners) | ||
return false; | ||
const l = this._listeners[id]; | ||
if (l) { | ||
const idx = this.__listener(l, fn, scope); | ||
if (idx === -1) { | ||
console.log(`attempt to remove unknown listener for "${id}": ${fn}`); | ||
} | ||
else { | ||
if (idx !== -1) { | ||
l.splice(idx, 1); | ||
console.log(`removed listener for "${id}": ${fn}`); | ||
return true; | ||
} | ||
} | ||
return false; | ||
}, | ||
notify(e) { | ||
this._listeners = this._listeners || {}; | ||
if (e.target === undefined) { | ||
e.target = this; | ||
} | ||
if (!this._listeners) | ||
return; | ||
e.target === undefined && (e.target = this); | ||
inotify_dispatch(this._listeners[e.id], e); | ||
@@ -69,3 +68,3 @@ inotify_dispatch(this._listeners[api.EVENT_ALL], e); | ||
return i; | ||
}, | ||
} | ||
}); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const mixin_1 = require("../mixin"); | ||
// tslint:disable-next-line | ||
exports.IWatch = mixin_1.mixin({ | ||
@@ -15,3 +14,4 @@ addWatch(id, fn) { | ||
removeWatch(id) { | ||
this._watches = this._watches || {}; | ||
if (!this._watches) | ||
return; | ||
if (this._watches[id]) { | ||
@@ -24,9 +24,9 @@ delete this._watches[id]; | ||
notifyWatches(oldState, newState) { | ||
const w = (this._watches = this._watches || {}); | ||
const keys = Object.keys(w); | ||
for (let i = keys.length - 1; i >= 0; i--) { | ||
const id = keys[i]; | ||
if (!this._watches) | ||
return; | ||
const w = this._watches; | ||
for (let id in w) { | ||
w[id](id, oldState, newState); | ||
} | ||
}, | ||
} | ||
}); |
{ | ||
"name": "@thi.ng/api", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "Common, generic types & interfaces for thi.ng projects", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
37972
37
774