Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: Scope related filters #165

Open
caillou opened this issue Dec 14, 2016 · 0 comments
Open

Discussion: Scope related filters #165

caillou opened this issue Dec 14, 2016 · 0 comments

Comments

@caillou
Copy link

caillou commented Dec 14, 2016

I need the keyboard events to trigger within <input> fields for certain scopes. I have come up with the following solution:

const registerKeymasterScopeFilter = require('./register-keymaster-scope-filter');
registerKeymasterScopeFilter('input-scope', (e) => (true));

with the register-keymaster-scope-filter.js module looking as follows:

const keymaster = require('keymaster')
const defaultFilter = keymaster.filter
const scopeFilters = {}

keymaster.filter = (e) => {
  let currentScope = keymaster.getScope()
  let scopeFilter = scopeFilters[currentScope]

  if (typeof scopeFilter === 'function') {
    return scopeFilter(e)
  }

  return defaultFilter(e)
}

module.exports = (scope, filter) => {
  scopeFilters[scope] = filter
}

What are your thoughts on this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant