This is my proposal for revamping the YUI Core Feature detection system.
- 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
- Create
YUI.Features
off the global objectYUI.Features.add('name', fn)
YUI.Features.has('name')
orYUI.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 globalYUI.Features
- This also requires
Y.UA
to be moved toYUI.UA
- This may also require refactoring
YUI.Env
too. - Refactor all "internal" seed tests (
Y.Array
/Y.Object
) to use newYUI.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 theconditional
so the old manual tests still work, UA still works, thenfeature
polls the Feature tests.
- Maybe adding a
- Build step to generate content
- Tool to list/view current registered modules
- Shortcut to help create them
- 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.