Giter VIP home page Giter VIP logo

minivents's Introduction

minivents Build Status

http://allouis.github.io/minivents/

API

on : Listen to event. Params { type:String, callback:Function | context:Object }. Returns target.

off : Stop listening to event. Params { type:String | callback:Function }. Returns target.

emit: Emit event. Params { type:String | data:Object }. Returns target.

Constructor Example

var sandbox = new Events();
    
sandbox.on("event", function(){
    // do stuff
});

sandbox.emit("event"); //does stuff

sandbox.off("event");

sandbox.emit("event"); //does not do stuff

Mixin Example

var sandbox = {
    otherStuff: true
};

Events(sandbox);

sandbox.on("event", function(){
    // do stuff
});

sandbox.emit("event"); //does stuff

sandbox.off("event");

sandbox.emit("event"); //does not do stuff

minivents's People

Contributors

allouis avatar amareis avatar francisc avatar gr2m avatar hypercubed avatar jlgrall avatar kevadsett avatar remy avatar sth avatar vixalien avatar zored avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minivents's Issues

Wrong meta

bower minivents#*   invalid-meta The "main" field cannot contain minified files
bower minivents#*   mismatch Version declared in the json (2.0.1) is different than the resolved one (2.0.2)

version field now deprecated in bower, you can remove it. Also, you have bower.json and .bower.json files, is it really matters?

emit calling callbacks

Emit calls the callback of an event in reverse order of which they were added.
this an fix fixed by using a for loop instead of a while loop in the emit method.

Which is more desirable functionality? Personally I use a mediator to decide when things should happen and don' functionality on the order in which I declare events.

Would the switch be something people want to see?

Really need a build process

Just for the minification of minivents.js - it's not great for contributors to not be able to run a build script.

Add ability to mixin to other objects

Looks great - I've been looking for a lightweight events object for some time.

My only barrier to using minivents is that my typical use-case for events would be to mixin an event to my existing object rather than create a dedicated object.

Minievents might have greater appeal if you considered that use as well!

(and if I've missed something and this is actually easy to do, please let me know!)

Thanks!

Request to add .once() method

I have some events I'd like to only have bound one time.

I'm imagining you're intending for this to be small library, so not sure where this fits into your design goals.

I wouldn't mind extending it myself, only that's not an option because the events object is hidden inside the Events constructor.

If I were to use .off() before calling .on() so as to prevent adding the event handler multiple times I could accidentally remove events I needed to hold onto.

v1.2.0 release is old and busted but installs over latest (v.1.1.7) -- jspm

In a current project, I am using jspm as my package manager. It allows me to install minivents as a dependency by doing:

jspm install minivents=github:allouis/minivents

Sweet! Except...

jspm expects that the libs it installs track releases using Semantic Versioning. This means that v1.1.2 < v1.1.7 < v1.2.0

The latest release for this lovely project is v1.1.7, which is stable. However, there also exists a release v1.2.0 from Feb 26 2014 -- which is broken. So this means that when I install this project as a dependency, I get the old and busted version :(

Could you kindly delete that version?

Workaround

Just in case someone else has this same issue, here's the workaround until its fixed:

jspm install minivents=github:allouis/[email protected]

Issue when emitting and removing

Hi,
I've found a bug when you register multiple callbacks to an event, then emit the event, and one of the callback unregister himself for this event, resulting in skipping the next callback.

I've forked your repo and fixed it.
Thanks

Passing arguments to event

It should be possible to send arbitrary arguments with the event. Eg

foo.on('myEvent', (arg1, arg2) => {
  ...
});
...
foo.emit('myEvent', arg1, arg2);

How to use context

Hello,

I thought this code will launch two alert windows with values 1 and 2 respectively:

var sandbox = new Events();
sandbox.on("event", function(){
    alert(1)
});

var another= new Events();
another.on("event", function(){
    alert(2)
}, sandbox);

sandbox.emit("event");

I thought it'll be similar to Backbone listenTo

Here is my plunkr demo.
Could you please provide more details for what context could be used ?

Cascading Events.emit bug

I've found that an Events instance could not trigger an event, that will trigger another event on the same Events instance.

The solution can be fixed by declaring variables list, j, i locally in .off and .emit
I've forked your repo and fixed the bug.

Do you want a merge request?

Off method bug

off method sets value of event object to undefined rather than removing it from the array using Splice, currently throws an error when off is used with a second parameter and then that event is triggered. Global off's work fine. eg sandbox.off("eventname")

bower support

could you add a bowed support ?
I tried to add by myself the bower.json, but i can't contribute :s
`{
"name": "minivents",
"version": "1.1.6",
"description": "Tiny eventing for javascript",

"main": "minivents.js",

"ignore": [
"*/.",
"node_modules",
"bower_components",
"test"
],
"dependencies": {},
"devDependencies": {}
}`

Is it possible to have trigger as an alias to emit?

I am evaluating this library for use in an existing project. I want to replace the current event system with this one. Support for trigger would be a great benefit since that is what the current event provider uses.

Is it possible to have it as an alias to emit? This would allow minievents to be a simple drop in replacements for cases where one does not need a full blown events provider.

Thanks for listening.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.