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

Handling scalar values with extract and length functions. #1576

Closed
seven-phases-max opened this issue Oct 3, 2013 · 1 comment
Closed

Handling scalar values with extract and length functions. #1576

seven-phases-max opened this issue Oct 3, 2013 · 1 comment
Milestone

Comments

@seven-phases-max
Copy link
Member

(Feature request)

I was about to pull length function implementation (as in #1542), but realized that it would first probably make sense to propose a minor improvement for the extract function since it's closely related.

Currently, a scalar value (e.g. any non-array/list value) handling by extract is somewhat undefined. Certain types just pass through while others rise a errors, for example:

results {
    c: extract(123, 1);   // OK, outputs c: extract(123, 1);
    d: extract(#123, 1);  // non_object_property_loadError: error evaluating function `extract`
    c: extract('123', 1); // undefined_methodError: Object 1 has no method 'genCSS'
    a: extract(name, 1);  // undefined_methodError: Object n has no method 'genCSS'
    // etc.
}

So my proposal is: both extract and length should treat a single value as an array of length 1. The rationale behind this is quite simple I think: any code working with an arbitrary number of values (as a variable(s) or a mixin argument(s)) would be able to handle both array/list and scalar input in the same uniform manner.
Here's a typical use-case example I think of:

.widget-1 {
    .transition(color);
}

.widget-2 {
    .transition(color, background-color, border-color);
}

.transition(@properties...) {
    .loop(length(@properties));
    .loop(@i) when (@i > 0) {
        .loop((@i - 1));
        transition+: extract(@properties, @i) 2s ease-out;
    }
}

CSS output:

.widget-1 {
  transition: color 2s ease-out;
}
.widget-2 {
  transition: color 2s ease-out, background-color 2s ease-out, border-color 2s ease-out;
}

That's it, no need for any conditionals, specialized mixin, etc...

Thanks.

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

2 participants