2.0.2 • Published 7 years ago

ts-base-class v2.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

BaseClass

Base class to extend. Like backbone events.

Installation

npm install ts-base-class --save

Interface path

/// <reference types="ts-base-class" />

For configure project:

npm install typescript -g
npm install tsd -g
npm run init 

For start test:

npm run test

Methods

  • on(eventName:string, handler:IHandler, context?:any):Base;
  • once(eventName:string, handler:IHandler, context?:any):Base;
  • off(eventName?:string, handler?:IHandler):Base;
  • listenTo(target:Base, eventName:string, handler:IHandler, context?:any):Base;
  • listenToOnce(target:Base, eventName:string, handler:IHandler, context?:any):Base;
  • stopListening(target?:Base, eventName?:string, handler?:IHandler):Base;
  • trigger(eventName:string, args?:Array):Base;
  • onLoad(callback:Callback):Base;
  • loaded():Base;
  • onReady(callback:Callback):Base;
  • ready():Base;
  • onState(state:string, callback:Callback):Base;
  • setState(state:string):Base;
  • hasState(state:string):boolean;
  • isLoaded():boolean;

Example

     /// <reference types="ts-base-class" />
     import {Base} from 'ts-base-class';
     
     class MyClass extends Base {
        //...
        
     }
     
     var $class = new MyClass();
     
     $class.on("Some:change", function (arg) {
        console.log(this instanceof MyClass); //true
        console.log(arg); //1
     });
     
     $class.on("Some", function (state:string, arg) {
        console.log(this instanceof MyClass); //true
        console.log(state); //"change"
        console.log(arg); //1
     });
     
     $class.trigger("Some:change", [1]);

Version: 2.0.2


License

Licensed under ISC

2.0.2

7 years ago

2.0.1

7 years ago

1.0.11

8 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago