Code Monkey home page Code Monkey logo

filter-event's Introduction

filter-event

mercury / vdom compatible event for taking a firehose of events and reducing to the ones you want.

Scenario

I was working on an app where I need to capture just the focus events (focusin, focusout) for a given input, then modify state. When using value-event/event, I can broadcast and receive the event, but this has 2 problems:

  1. Since the original event object and DOM element are de-coupled, it is not possible to know the type of event fired. I just know that there was AN event.
  2. A large number of events are being fired. Most of them are not important to me.

Solution

Added value-event/filter event. This works exactly like value-event/eventexcept that it takes a whitelist of event names that it will allow to pass. This allows event targeting without bringing any part of the event or DOM forward into the handler or channel.

Usage

var sendFilteredEvent  = require('value-event/filter.js');

var state = { 
  active: false
};
var active_handler = function(active) {
  state.active = active;
};
var text_handlers = [

  sendFilteredEvent(active_handler, true , {
    event_types: ['focusin']
  }), 

  sendFilteredEvent(active_handler, false, {
    event_types: ['focusout']
  })
];

Now the VDOM part

h('input', {
  'ev-event': text_handlers,
  name: 'dogs',
  type: 'text'
});

filter-event's People

Stargazers

 avatar

Watchers

 avatar  avatar

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.