abstract-object
Advanced tools
Comparing version 3.0.0-alpha.1 to 3.0.0-alpha.2
@@ -8,3 +8,3 @@ "use strict"; | ||
exports.default = void 0; | ||
var _eventable = _interopRequireDefault(require("./eventable")); | ||
var _eventsEx = require("events-ex"); | ||
var _stateable = _interopRequireDefault(require("./stateable")); | ||
@@ -16,4 +16,4 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
(0, _stateable.default)(EventableObject); | ||
(0, _eventable.default)(EventableObject); | ||
(0, _eventsEx.eventable)(EventableObject); | ||
var _default = EventableObject; | ||
exports.default = _default; |
@@ -12,2 +12,14 @@ "use strict"; | ||
const MAX_LISTENERS = 2e308; | ||
/* | ||
* eventable your class, add the following methods and event to your class | ||
* * Methods: | ||
* * dispatch(event, args[, callback]) | ||
* * dispatchError(error[, callback]) | ||
* * Events: | ||
* * initing: emit before the init method | ||
* * inited: emit after the init method | ||
* * destroying: emit before the final method | ||
* * destroyed: emit after the final method | ||
*/ | ||
exports.MAX_LISTENERS = MAX_LISTENERS; | ||
@@ -14,0 +26,0 @@ function eventableOptions(aOptions) { |
@@ -58,18 +58,10 @@ "use strict"; | ||
} | ||
return self.init.apply(this, arguments); | ||
return self.init.apply(self, arguments); | ||
} | ||
}); | ||
// Stateable.prototype.initialize = function() { | ||
// if (isFunction(this.init)) { | ||
// console.error('init method is deprecated, pls use initialize instead') | ||
// if (!Stateable.prototype.init) { | ||
// Stateable.prototype.init = (function() {}) | ||
// } | ||
// return this.init.apply(this, arguments) | ||
// } | ||
// } | ||
Stateable.prototype.finalize = function () { | ||
if ((0, _utilEx.isFunction)(this.final)) { | ||
(0, _utilEx.defineProperty)(Stateable.prototype, 'finalize', function () { | ||
const self = this.self || this; | ||
if ((0, _utilEx.isFunction)(this.super)) { | ||
return this.super.apply(self, arguments); | ||
} else if ((0, _utilEx.isFunction)(self.final)) { | ||
console.error('final method is deprecated, pls use finalize instead'); | ||
@@ -79,5 +71,5 @@ if (!Stateable.prototype.final) { | ||
} | ||
return this.final.apply(this, arguments); | ||
return self.final.apply(self, arguments); | ||
} | ||
}; | ||
}); | ||
Stateable.prototype._constructor = function () { | ||
@@ -84,0 +76,0 @@ (0, _utilEx.defineProperty)(this, '_objectState_', null); |
{ | ||
"name": "abstract-object", | ||
"version": "3.0.0-alpha.1", | ||
"version": "3.0.0-alpha.2", | ||
"description": "AbstractObject with Object State Events Support", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/snowyu/abstract-object", |
@@ -1,2 +0,2 @@ | ||
import eventable from './eventable' | ||
import {eventable} from 'events-ex' | ||
import stateable from './stateable' | ||
@@ -3,0 +3,0 @@ |
@@ -7,2 +7,13 @@ import {extend, isArray, isFunction, isUndefined} from 'util-ex' | ||
/* | ||
* eventable your class, add the following methods and event to your class | ||
* * Methods: | ||
* * dispatch(event, args[, callback]) | ||
* * dispatchError(error[, callback]) | ||
* * Events: | ||
* * initing: emit before the init method | ||
* * inited: emit after the init method | ||
* * destroying: emit before the final method | ||
* * destroyed: emit after the final method | ||
*/ | ||
export function eventableOptions(aOptions) { | ||
@@ -9,0 +20,0 @@ const result = {methods: {}, required: ['setMaxListeners', 'emit']} |
@@ -5,3 +5,3 @@ import {AdditionalInjectionMode, createAbilityInjector} from 'custom-ability' | ||
import additionalOptions from './eventable-options' | ||
import eventableOptions from './eventable-options' | ||
@@ -61,18 +61,12 @@ export const OBJECT_STATES = { | ||
} | ||
return self.init.apply(this, arguments) | ||
return self.init.apply(self, arguments) | ||
} | ||
}) | ||
// Stateable.prototype.initialize = function() { | ||
// if (isFunction(this.init)) { | ||
// console.error('init method is deprecated, pls use initialize instead') | ||
// if (!Stateable.prototype.init) { | ||
// Stateable.prototype.init = (function() {}) | ||
// } | ||
// return this.init.apply(this, arguments) | ||
// } | ||
// } | ||
defineProperty(Stateable.prototype, 'finalize', function() { | ||
const self = this.self || this | ||
Stateable.prototype.finalize = function() { | ||
if (isFunction(this.final)) { | ||
if (isFunction(this.super)) { | ||
return this.super.apply(self, arguments) | ||
} else if (isFunction(self.final)) { | ||
console.error('final method is deprecated, pls use finalize instead'); | ||
@@ -82,5 +76,5 @@ if (!Stateable.prototype.final) { | ||
} | ||
return this.final.apply(this, arguments) | ||
return self.final.apply(self, arguments) | ||
} | ||
} | ||
}) | ||
@@ -118,3 +112,3 @@ Stateable.prototype._constructor = function() { | ||
mode: AdditionalInjectionMode.target, | ||
getOpts: additionalOptions, | ||
getOpts: eventableOptions, | ||
} | ||
@@ -121,0 +115,0 @@ } |
@@ -11,3 +11,2 @@ import chai, {assert, expect} from 'chai' | ||
import createObject from 'inherits-ex/lib/createObject' | ||
// import {eventable} from '../src/eventable' | ||
import {eventable} from 'events-ex' | ||
@@ -14,0 +13,0 @@ |
44157
29
1016