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
Proposal: new object structure for test definitions #1246
Comments
I think this is exactly the type of thing that has to happen. Thank you so much for writing all of this up. I would be concerned with accidentally leaking globals, since variables would have to be defined multiple times. Also, would we be able to unset all Built-in helpers
I would be concerned about making tests difficult for newcomers to grok. keeping the amount of properties to an absolute minimum would be a good goal to have. If its just a matter of a small amount of sugar, I would probably be against it. prefixed
I know this is just pseudo code, but I don't see why we would need to pass in navigator. we could just look that up when needed.
again, worried about tests seeming too magical to newbies. but that is clean as hell. asyncAsync stuff looks wonderful. much cleaner than the current. though it seems like "result" should be the "test" code. so more like Modernizr.addTest({
name: 'asyncTest',
async: function() {
var i = new Image();
i.onload = this.test;
i.onerror = this.test;
},
test: function (event) {
if (event.type == 'load') return true;
return false;
}) that way |
I love all of this, but I have to be the one to ask if we're solving a When I build websites these days, I can rarely use 3 tests without getting I spose I'd like to see the perf impact of this with our most popular 6 (Forgive my thumbs/2am brain.) |
It’s worth remembering that a lot of sites still end up in the wild with the dev version, and as much as we harp on at people about custom builds (including throwing warnings in the console), I’d feel more comfortable if we were doing everything in our power to minimise this hit. One tweak I’d make – specifying the property name as the first arg (as it is now), so the object syntax just becomes an alternative way of defining your test “function”: Modernizr.addTest('propname', {
...
}); But even with this, I appreciate the structure might be more complex to newcomers, which is a definite downside. Science is the way to approach this. I’ll build a prototype on a branch, do some tests with various different builds, and we can look at the numbers and decide what to do. |
This structure is much more straightforward to me. ✨ it. |
Not expecting us to act on this any time soon, but thought I’d throw my brain-dump out there.
Ok, so I got a bit carried away while looking at #1224. Basically there’s a limit to how much we can optimise things like
testStyles()
with our tests as they are at the moment: just a chunk of code to test a thing. I’ll carry on working on it though, there are definitely some savings which can be made, but I had some other ideas too.Problem:
Modernizr’s current
addTest()
test structure makes it hard to separate DOM manipulation and DOM checking. Interleaving these things is poor for performance, because it results in a large number of restyle/layout operations.Solution:
Restructure how tests are defined, such that DOM manipulation and DOM checking can be separated. The runner can then perform all DOM state setup for all tests together, and then perform all the necessary checking together.
Proposal: new test format
Modernizr.addTest()
could be adapted to accept an object as a sole argument:The test runner would then be able to run each test’s
setUp
phase, one after the other: if these are written to avoid reading from the DOM, they’ll rattle through without any expensive restyle/layout operations.It would then do a single repaint, before running all of the
test
phases; again, as long as these don’t modify the DOM in any way, the browser won’t have to restyle/layout.Of course there will be some which can’t be split like this, but I think they’re rare.
Example: (Compare with the current version)
Simple tests
Like the current API,
test
could still just be a Boolean value:Built-in helpers
Common test patterns could be invoked using special attributes. These could be designed to split their DOM manipulation and interrogation efficiently.
testProp / testValue
testProp
performs a test for the named CSS property, usingtestValue
if provided (andCSS.supports()
if available); the result is passed to thetest
method:Or omit the
test
function for the Boolean result of the property check will be used implicitly:It would test for prefixed versions too by default, unless you’ve set the
noPrefixes
global option, or you setusePrefixes: false
for the specific test:useStyles
useStyles
can be used to prime the test with some style rules. The special token#m!
will be replaced with a selector targeting theelem
(which is determined at runtime):prefixed
prefixed
can be used too, and its result would be passed totest
, liketestProp
; we can name argument something more useful:If
test
is omitted then the test result will be the result ofprefixed()
, cast to a Boolean:And there are inevitable combinations of these – we’d have to agree an order for the arguments passed to
test
, etc.Async tests
I think this structure better facilitates async tests too, with a helpful
result
method:Interdependencies
We’d still have our AMD wrappers around all of these (I’ve omitted them so far for brevity), but they’d be used as they are now when a test depends on another:
The text was updated successfully, but these errors were encountered: