AbstractObject with Object State Supports and `free` method provides.
npm install @crabas0npm/corporis-consequatur-doloremAbstractObject with Object State Supports and free method provides.
The derived class should overwrite the initialize and finalize methods.
+ add the state-able ability to any class.
-
* decoupled the @crabas0npm/corporis-consequatur-dolorem completely.
* All parts can be used individually.
* stateable = require('@crabas0npm/corporis-consequatur-dolorem/ability')
* eventable = require('events-ex/eventable')
* refCountable = require('ref-object/ability')
*
+ the new EventableObject can be as AbstractObject@v1.x
*
+ the new EventableRefObject can be as RefObject@v1.x
+ add the eventable function to eventable any class('@crabas0npm/corporis-consequatur-dolorem/eventable').
* use the eventable plugin(events-ex) to implement eventable object.
- move all util functions to util-ex
- move enhanced inheritance Functions to inherits-ex.
- move AbstractError to abstract-error
* AbstractObject inherits from EventEmitter.
* RefObject inherits from AbstractObject
* AbstractError
add the Object State Supports and free method to your class directly.
``coffee
stateable = require '@crabas0npm/corporis-consequatur-dolorem/ability'
module.exports = class AbstractObject
stateable AbstractObject
`
Note: the eventable ability must be after the stateable. like this:
`coffee
stateable = require '@crabas0npm/corporis-consequatur-dolorem/ability'
eventable = require 'events-ex/ability'
class MyObject
stateable MyObject
eventable MyObject # MUST BE after stateable
`
* Methods:
* create(class, ...): the create class method uses to create a new object instance(the util.createObject is the same function).class
* : the class constructor to create a new instance....
* : the left arguments will be passed into the class constructor.createWith
* (class, arguments): the createWith class method uses to create a new object instance(the util.createObjectWith is the same function).class
* : the class constructor to create a new instance.arguments
(array)*: the arguments will be passed into the class constructor.initialize(...)
* : abstract initialization method after a new instance creating....
* : the constructor's arguments should be passed into initialize method.finalize
* (...): abstract finalization method before the instance destroying....
* : the free(destroy)'s arguments should be passed into finalize method.init(...)
(deprecated) : abstract initialization method after a new instance creating.*...
* init method is deprecated, pls use initialize method instead
* : the constructor's arguments should be passed into init method.final
(deprecated) (...): abstract finalization method before the instance destroying.*...
* final method is deprecated, pls use finalize instead
* : the free(destroy)'s arguments should be passed into final method.free
* (...): free the class instance....
* : optional arguments will be passed into final method to process.isIniting
* (), isInited(),isDestroying(), isDestroyed() object state testing methods:
* to test object state
* only for EventableObject:
* Methods:
* dispatch(event, args[, callback]): dispath an event or callbackevent
* : the event nameargs
* : the args are passed to event or callbackcallback
* : optional, it will not dispatch event if the callback is exists, unless the callback return false.dispatchError
* (error[, callback]):error
* : the error instance.callback
* : optional, it will not dispatch 'error' event if the callback is exists, unless the callback return false.'initing'
* Events:
* : emit before the initialize method'inited'
* : emit after the initialize method'destroying'
* : emit before the finalize method'destroyed'
* : emit after the finalize method
RefObject has moved to ref-object
The RefObject is derived from AbstractObject. and add the RefCount and AddRef/Release Supports.
* methods:
* release()/free(): Decrements reference count for this instance.addRef()
If it is becoming less than 0, the object would be (self) destroyed.
* : Increments the reference count for this instance
and returns the new reference count.
`coffee
AbstractObject = require('@crabas0npm/corporis-consequatur-dolorem')
inherits = require('inherits-ex')
createObject = AbstractObject.create
#or createObject = require('inherits-ex/lib/createObject')
class MyObject
inherits MyObject, AbstractObject
initialize: (@a, @b)->
@cache = {}
finalize: ->
@cache = null
myObj = createObject(MyObject, 1, 2)
, you MUST remember this:class MyObject
inherits MyObject, RefObject
constructor: ->
# must call super method here:
super
initialize: (@a,@b)->
@cache = {}
finalize: ->
@cache = null
`
the javascript:
`js
var AbstractObject = require('@crabas0npm/corporis-consequatur-dolorem')
var RefObject = require('ref-object')
var inherits = require('inherits-ex')
var createObject = AbstractObject.create
//or var createObject = require('inherits-ex/lib/createObject')
//if you do not wanna to use the 'AbstractObject.create'(createObject):
var MyObject = function() {
//super call
MyObject.__super__.constructor.apply(this, arguments);
}
// or, this MUST use the 'AbstractObject.create'(createObject)
var MyObject = function(){}
inherits(MyObject, RefObject)
MyObject.prototype.initialize = function(a,b) {
this.a = a
this.b = b
this.cache = {}
}
MyObject.prototype.finalize = function() {
this.cache = null
}
var myObj = createObject(MyObject, 1, 2)
//or this, must overwrite the constructor and call the super constructor.
var myObj = new MyObject(1,2)
``
It has moved to abstract-error.
Moved to inherits-ex.
Moved to util-ex.