Comments (6)
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.
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.
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.
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.
O.K., then. I withdraw my request. I will simply build management around the subscriptions.
Thank you.
from jwerty.
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)
- Keyboard shortcut to launch modal window... HOT 2
- Bugs with some symbols (OSX) HOT 2
- Typo on the website
- ctrl+n binding? HOT 1
- Need for an ability to detect if ctrl/shift/alt key is active at current event HOT 3
- Unbind key will not work
- IE 8 issue when binding to enter key in textboxes HOT 2
- Key combo triggers on single key. HOT 1
- Rm canBridge.js
- Firing actually doesn't do anything in latest Chrome?
- Comparison with established keyboard libraries HOT 1
- Minus (-) key doesn't work HOT 2
- Please push latest version to npm
- jwerty.key(...) returns nothing
- cmd+l not working in Safari
- get actual keys pressed when matching regex or optional HOT 1
- document using + sign HOT 4
- Difference between source code and archives/npmjs versions HOT 2
- Unbind doesn't work. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jwerty.