npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crisp-event

v0.5.2

Published

Object event with repeater, picker and optional asynchronous.

Downloads

17

Readme

Crisp.EventJS

Object event with repeater, picker and optional asynchronous.

Build Status NPM Downloads NPM Version

var myObject = Crisp.utilCreate({ ns: 'util.event' }).objIni();

myObject.eventListener({
  listen: function( e ) {
    console.log('Listen');
  }
});
console.log('Wait');

myObject.eventTrigger();

// logs:
// Wait
// Listen

Index Table

Getting Started

Server-Nodes

Use Node Package Manager (npm) to install crisp-event for Node.js and io.js

$ npm install crisp-event
// use package
require("crisp-event");

or use the OpenCrisp UtilJS wraper

$ npm install crisp-util
// use package
require("crisp-util");

Web-Clients

Use Bower to install crisp-event for Browsers APP's and other front-end workflows.

$ bower install crisp-event
<!-- use package -->
<script type="text/javascript" src="dist/crisp-event.min.js"></script>

or use the OpenCrisp UtilJS wraper

$ bower install crisp-util
<!-- use package -->
<script type="text/javascript" src="dist/crisp-util.min.js"></script>

Development

Use Git to clone Crisp.EventJS from GitHub to develop the repository with Grunt

# Clone:
$ git clone https://github.com/OpenCrisp/Crisp.EventJS.git

# Build: test, concat, test, minify, test
$ grunt

# Test: original sourcecode for developer (included in build)
$ grunt t

# Run all test-scripts on Unix
$ sh grunt-tests.sh

Usage

How to use Crisp.EventJS with JavaScript.

Crisp.defineEvent()

How to use Crisp.defineEvent( object [, option ]) module.

var myObject = {};

// initialice event property functions on myObject
Crisp.defineEvent( myObject );

// or with manual property name of event and parent 
Crisp.defineEvent( myObject, {
    // default: __event__
    event: '__myevent__',       // manual set the name of event cach
    // default: __parent__
    parent: '__myparent__'      // manual set the name of parent reference
});

Crisp.utilCreate()

How to use Crisp.utilCreate( option ) with util.event namespace.

var myObject = Crisp.utilCreate({
    ns: 'util.event'
}).objIni();

EventJS function

.eventListener()

How to use .eventListener( option ) on myObject

// listen for all triggert events
myObject.eventListener({
  listen: function( e ) {}
});

option.self (eventListener)

works with .eventTrigger() and .eventPicker()

// set self as alternate for apply thisArg
var thisArg = {};
myObject.eventListener({
  self: thsiArg,
  listen: function( e ) {
    this === thisArg;  // true
  }
});

option.async (eventListener)

works with .eventTrigger() and .eventPicker()

// set asynchronous callback for listen:function
myObject.eventListener({
  async: true,
  listen: function( e ) {}
});

option.action (eventListener)

works with .eventTrigger() and .eventPicker()

// set right namespase string filter
myObject.eventListener({
  action: 'insert',
  listen: function( e ) {}
});

// set an expandable RegExp filter like action:'insert'
myObject.eventListener({
  action: /(^|\s)insert($|\s|\.)/,
  listen: function( e ) {}
});

// set multi right namespase string filter with space seperator
myObject.eventListener({
  action: 'insert update',
  listen: function( e ) {}
});

// set an expandable RegExp filter like action:'insert update'
myObject.eventListener({
  action: /(^|\s)(insert|update)($|\s|\.)/,
  listen: function( e ) {}
});

option.path (eventListener)

works with .eventTrigger() and .eventPicker()

// set 
myObject.eventListener({
  action: /(^|\s)(insert|update)($|\s|\.)/,
  listen: function( e ) {}
});

option.noteList (eventListener)

works with .eventPicker()

// filter notes in specified list 
myObject.eventListener({
  noteList: 'merge',
  listen: function( e ) {}
});

option.noteAction (eventListener)

works with .eventPicker()

// set filter of note action
myObject.eventListener({
  noteAction: 'delete',           // or RegExp like option.action
  listen: function( e ) {}
});

option.notePath (eventListener)

works with .eventPicker()

// set filter of note path
myObject.eventListener({
  notePath: 'doc.b',
  listen: function( e ) {}
});

.eventTrigger()

How to use .eventTrigger( option ) on myObject

var myObject = Crisp.utilCreate({ ns: 'util.event' }).objIni();

myObject.eventListener({
  listen: function( e ) {
    console.log('Listen');
  }
});
console.log('Wait');

myObject.eventTrigger();

// logs:
// Wait
// Listen

option.repeat (eventTrigger)

// set repeat for trigger parent objects
var myObject = Crisp.utilCreate({
    ns: 'util.event',
    options: {
        parent: { proWri: true }
    }
}).objIni();

var myChild = myObject.objClone().objIni({
    parent: myObject
});

myObject.a = myChild;

myChild.eventListener({
    listen: function( e ) {
        console.log('Listener: Child');
    }
});

myObject.eventListener({
    listen: function( e ) {
        console.log('Listener: Object');
    }
});
console.log('JSON', myObject.xTo() );

myChild.eventTrigger({
    repeat: true
});

// logs:
// JSON {"a":{"b":"B"}}
// Listener: Child
// Listener: Object
// End

option.exporter (eventTrigger)

var myObject = {};
Crisp.defineEvent( myObject );

myObject.eventListener({
    listen: function( e ) {
        console.log('Listener');
    }
});
console.log('Wait');

myObject.eventTrigger();

myObject.eventTrigger({
    exporter: myObject
});
console.log('End');

// logs:
// Wait
// Listener
// End

option.action (eventTrigger)

var myObject = {};
Crisp.defineEvent( myObject );

myObject.eventListener({
    action: 'change',
    listen: function( e ) {
        assert.strictEqual( 'change', e.action );
        assert.strictEqual( myObject, this );
        assert.strictEqual( myObject, e.self );
    }
});

myObject.eventTrigger({
    action: 'change'
});

option.path (eventTrigger)

var myObject = {};
Crisp.defineEvent( myObject );

myObject.eventListener({
    path: 'doc',
    listen: function( e ) {
        assert.strictEqual( 'doc', e.path );
        assert.strictEqual( myObject, this );
        assert.strictEqual( myObject, e.self );
    }
});

myObject.eventTrigger({
    path: 'doc'
});

option.args (eventTrigger)

var thisArg = {};

var myObject = Crisp.utilCreate({
    ns: 'util.event'
}).objIni();

myObject.eventListener({
    listen: function( e ) {
        assert.strictEqual( myObject, this );
        assert.strictEqual( thisArg, e );
    }
});

myObject.eventTrigger({
    args: thisArg
});

.eventPicker()

How to use .eventPicker( option ) on myObject

var myObject = Crisp.utilCreate({ ns: 'util.event' }).objIni();

myObject.eventListener({
  listen: function( e ) {
    console.log('Listen:', e.action, e.List().xTo() );
  }
});

var pickerCache = {};
var picker = myObject.eventPicker({
    cache: pickerCache
});

picker.Note({
    action: 'update'
});
console.log('Wait');

picker.Talk();
console.log('End')

// logs:
// Wait
// Listen: task [{"action":"update"}]
// End

option.cache (eventPicker)

// Listener wait for the last Talk() on the same cache
var myObject = Crisp.utilCreate({ ns: 'util.event' }).objIni();

myObject.eventListener({
  listen: function( e ) {
    console.log('Listen:', e.action, e.List().xTo() );
  }
});

var pickerCache = {};
var picker = myObject.eventPicker({
    cache: pickerCache
});

{
    var sub_picker = myObject.eventPicker({
        cache: pickerCache
    });

    sub_picker.Note({
        action: 'insert'
    });
    console.log('Wait 0');

    sub_picker.Talk();
}

picker.Note({
    action: 'update'
});
console.log('Wait 1');

picker.Talk();
console.log('End')

// logs:
// Wait 0
// Wait 1
// Listen: task [{"action":"insert"},{"action":"update"}]
// End

option.action (eventPicker)

var myObject = {};
var pickerCache = {};

Crisp.defineEvent( myObject );

myObject.eventListener({
    action: 'changed',
    listen: function( e ) {
        assert.strictEqual( myObject, this );
        assert.strictEqual( myObject, e.self );
    }
});

var picker = myObject.eventPicker({
    action: 'changed',
    cache: pickerCache
});

picker.Note({
    action: 'update'
});

picker.Talk();

option.path (eventPicker)

var myObject = {};
var pickerCache = {};

Crisp.defineEvent( myObject );

myObject.eventListener({
    path: 'doc.a',
    listen: function( e ) {
        assert.strictEqual( myObject, this );
        assert.strictEqual( myObject, e.self );
    }
});

var picker = myObject.eventPicker({
    path: 'doc.a',
    cache: pickerCache
});

picker.Talk();

option.empty (eventPicker)

var myObject = {};
var pickerCache = {};

Crisp.defineEvent( myObject );

myObject.eventListener({
    listen: function( e ) {
        assert.strictEqual( '[]', e.List().xTo() );
        assert.strictEqual( myObject, this );
        assert.strictEqual( myObject, e.self );
    }
});

var picker = myObject.eventPicker({
    empty: true,
    cache: pickerCache
});

picker.Talk();

.eventRemove()

How to use .eventRemove( event ) on myObject

var myObject = Crisp.utilCreate({ ns: 'util.event' }).objIni();

var eventObject = myObject.eventListener({
  listen: function( e ) {
    console.log('Listen');
  }
});
console.log('Wait 0');

myObject.eventTrigger();

myObject.eventRemove( eventObject );
console.log('Wait 1');

myObject.eventTrigger();

console.log('End')

// logs:
// Wait 0
// Listen
// Wait 1
// End

Links