1.1.0 • Published 5 years ago

@latel88/monokit v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

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();
1.1.0

5 years ago

1.0.11

5 years ago

1.0.10

6 years ago

1.0.8

6 years ago

1.0.9

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago