Git Product home page Git Product logo

Comments (6)

makoConstruct avatar makoConstruct commented on July 30, 2024

It doesn't sound like it's necessary in your use case, you could just change what your onUpKey and onDownKey callbacks do according to an external variable, no?

Anyway, it should be implemented. If the _context objects you're referring to are as the return values of jwerty.event, it'd be a one line patch.

If, however, you want the _context objects to be the callbacks, or the context the callbacks are to be called in, or a pair of both of them, we would need a way of storing a mapping from (keycode, _context) to the binding object. There are a few ways of accomplishing this.

  • We could use es6 maps but this would not work on ie10-, so no we couldn't really use es6 maps.
  • Or we could store the binding object in _context as .jwerty_binding or something. Not pretty, especially considering we want to maintain a mapping from (callback, context), but instead we have to pick just one and find a way to work with that.

from jwerty.

estaylorco avatar estaylorco commented on July 30, 2024

Since I'm actually mapping about a dozen keys, I don't feel that flags are elegant. They just don't fit the general case.

The _context in this case is the keyboard context (DOM selector). I simply imagined that we would have a compound dictionary key made up of the key combination and the keyboard context. For example, we wouldn't want to accidentally unbind all up keys, perhaps just the up key in a particular keyboard context.

Thinking out loud, I'm seeing a dictionary that might look like this:

[ { { key: keyCombo: 'up', selector: '#someDiv'}, subscription: h } }, 
  {...}, 
  {...}
];

Does that make sense?

from jwerty.

makoConstruct avatar makoConstruct commented on July 30, 2024

If and only if you mean

{
  ['up', '#somediv']: subscription
  ['down', '#somediv']: othersubscription
  ...
}

Though we'd probably store the keys as concatenations of the keycode and the selector rather than an array.

'Fraid that may not be be enough of-popular-interest to land a place on @keithamus's 1.5kb arc?

from jwerty.

keithamus avatar keithamus commented on July 30, 2024

If jwerty were to keep a mapping of bound keys, that could cause memory leaks which would be trivial to surface, take for example the following:

jwerty.key('↓', function () {...}, '#myList');
// later on on the code;
$('#myList').remove();

By removing the element, but not clearing up the internal jwerty key binding, jwerty now has a reference to a key binding on a dom element that doesnt exist, but doesn't know about it - therefore a memory leak. The only way around this, to my knowledge, is if we added DOM mutation handlers to every element we bind to - but this is not compatible with lots of browsers and is way too heavyweight.

Currently where jwerty returns an unbind function makes good sense, because there are no references stored in jwerty, it just passes the unbind function - which you have to manage yourself via your own classes, where you have much better knowledge of the application logic than jwerty does.

from jwerty.

estaylorco avatar estaylorco commented on July 30, 2024

O.K., then. I withdraw my request. I will simply build management around the subscriptions.

Thank you.

from jwerty.

keithamus avatar keithamus commented on July 30, 2024

Thanks @estaylorco. Sorry that jwerty can't help you here. If anyone can come up with an idea that wont cause memory leaks, I'll be all ears 😄.

from jwerty.

Related Issues (20)

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.