1.1.0 • Published 5 years ago
@latel88/monokit v1.1.0
Monokit
Base class library.
how to use
- install
npm install @latel88/monokit
- CJS
const Monokit = require( "@latel88/monokit" ).default;
- ESM
import Monokit from "@latel88/monokit";
exsample
- extend
class Entity extends Monokit
{
constructor ()
{
super(
{
...initialized
} );
}
}
const Entity = Monokit.extend(
{
constructor ()
{
this._super( "constructor",
{
...initialized
} );
}
} );
const Entity = Monokit.extend( {} );
const Enemy = Entity.extend( {} );
- create
const entity = new Entity( ...arguments );
const entity = Entity.create( ...arguments );
const entity = Entity.singleton( ...arguments );
//true
entity === Entity.singleton();
const entity = Entity.singleton( ...arguments );
//delete static instance
entity.destroy();
//new instance
const other = Entity.singleton( ...arguments );
//pop pool
const entity = Entity.pool( ...arguments );
//stack pool
entity.destroy();
const entity = Entity.pool();
Object.defineProperty( entity, "life",
{
value: 100,
configurable: false
} );
//Not stack pool
if (entity.destroy() === false)
{
throw "Can not stack instance.";
}
- listener
const entity = new Entity();
function callback ( event )
{
event.type;//listener name
event.target;//call instance
event.timestamp;//trigger time
event[ ...parameters ];
}
//add
entity.on( "load", callback );
//remove
entity.off( "load", callback );
//trigger
entity.fire( "load", { ...parameters } );
class Entity extends Monokit
{
onload ( event )
{
}
}
const entity = new Entity();
entity.fire( "load", { ...parameters } );
class Entity extends Monokit
{
ondestroy ( event )
{
}
}
const entity = new Entity();
entity.on( "destroy", () => );
entity.destroy();