Skip to content

Instantly share code, notes, and snippets.

@davglass
Created February 1, 2013 15:21
Show Gist options
  • Save davglass/4691926 to your computer and use it in GitHub Desktop.
Save davglass/4691926 to your computer and use it in GitHub Desktop.
Proposal for new YUI.Features

New YUI Feature Detection

This is my proposal for revamping the YUI Core Feature detection system.

Problem Space

  • 90% of our so-called "Feature Tests" are actually Loader conditional modules.
  • Some "free-flowing" tests in DOM modules.
  • Not sharable
  • Hard to find
  • Possible duplicates
  • Instance Based
    • Means that each instance re-runs tests that have already been computed
  • Not cached
  • Not named for easy lookups

Proposed Solution

  • Create YUI.Features off the global object
    • YUI.Features.add('name', fn)
    • YUI.Features.has('name') or YUI.Features.supports('name')
    • Store all results in exposed private: YUI.Features._results = {};
    • add will execute, then cache the result. Never executing twice.
    • No tests are executed up front, only on first access.
    • Modules will have access to all the tests because they will be in the seed.
      • Caveat: This may make the seed larger, so care should be taken when creating tests.
  • Alias Y.Features to global YUI.Features
  • This also requires Y.UA to be moved to YUI.UA
  • This may also require refactoring YUI.Env too.
  • Refactor all "internal" seed tests (Y.Array/Y.Object) to use new YUI.Features.
  • Move all conditionals out of Loader and into a new module (TBD below)
  • Teach Loader to use the new tests
    • Maybe adding a feature property to the conditional so the old manual tests still work, UA still works, then feature polls the Feature tests.
  • Build step to generate content
    • Tool to list/view current registered modules
    • Shortcut to help create them

Things to Determine

  • Where should these things live?
    • Current tests are per module, which I think is wrong. Feature tests should not be module specific.
    • I'm proposing src/features/<tbd>/<testname>.js
  • Should we still support the old way for a while?
    • This "may" be a breaking change, that's up for discussion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment