JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q37386F
  • License MIT

website user preference API

Package Exports

  • ux

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ux) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ux

website user preference API

ux uses localStorage to remember features such as user preferences or display modes.

API

Methods

Notes

  • feature can be any string
  • features are either enabled, disabled, or unknown

####ux.enabled()

  • Get an array containing the names of all enabled features
  • @return array

####ux.enabled(feature)

  • Test if feature is enabled
  • @return boolean

####ux.disabled()

  • Get an array containing the names of all disabled features
  • @return array

####ux.disabled(feature)

  • Test if feature is disabled
  • @return boolean

####ux.known()

  • Get an array containing the names of all known features
  • @return array

####ux.known(feature)

  • Test if feature is known (either enabled or disabled)
  • @return boolean

ux.enable(feature)

  • Enable a feature and trigger listeners

ux.disable(feature)

  • Disable a feature and trigger listeners

ux.toggle(feature)

  • Toggle (either enable or disable) a feature and trigger listeners

ux.forget(feature)

  • Forget feature and trigger listeners

ux.forget()

  • Forget all features

Emitters have emitter methods

  • .on(feature, listener)
  • .off(feature?, listener?)
  • .once(feature, listener)
  • .emit(feature, ...args)

Emitter syntax

  • ux.enable.on(feature, listener)
  • ux.disable.on(feature, listener)
  • ux.forget.on(feature, listener)
  • ux.enable.off(feature?, listener?)
  • ux.disable.off(feature?, listener?)
  • ux.forget.off(feature?, listener?)
  • etc.

Emitter example

// Listen for when 'crazycolors' is enabled
ux.enable.on('crazycolors', function(feature) {
  document.querySelector('html').classList.add(feature)
  console.log(feature + ' enabled')
})

// Enable 'crazycolors'
ux.enable('crazycolors')

You normally would want to also listen for when the same feature is disabled and do an opposing action. You're also likely to have multiple (and maybe related) features. ux doesn't care what your features do. It only provides the API for enabling, disabling, and remembering them. Do what makes sense for your features and users :)

Contribute

To make edits, first fork the repo, clone your fork, and cd into it. Run tests via the commands below and/or in a browser. Make edits in src and test as needed. Push your changes and then submit a pull request. Builds (in the project root) are created later via grunt and should not be changed in pull requests. CLI commands require node and the grunt-cli on your system.

$ npm install -g grunt-cli # install grunt-cli if you haven't already
$ npm install # install devDependencies from package.json
$ grunt jshint:sub # lint sub dirs
$ grunt test # run tests

Fund

Support this project by tipping the developer =)

License

MIT