-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add for(integerVal) counting loops #709
Conversation
result.push( | ||
options.fn( options.scope | ||
.add({ index: i }, { special: true }) | ||
.addLetContext(variableScope) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should create a variable?
{{# for(ittr of this.integerValue) }}
<li>{{scope.index}}: {{ ittr }}</li>
{{/ for }}
I sorta think access should be only through scope.index
like: {{# for( this.integerValue ) }} {{scope.index}} {{/for}}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, I think it's ok to make {{# for(ittr of this.integerValue) }}
work. But I wouldn't show this as the main way of using it.
helpers/-for-of.js
Outdated
@@ -14,6 +14,23 @@ var bindAndRead = function (value) { | |||
} | |||
}; | |||
|
|||
function forOfInteger(integer, variableName, options) { | |||
var result = []; | |||
for (var i = 0; i < integer; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems there's some indentation inconsistency
@@ -65,6 +65,32 @@ | |||
``` | |||
@codepen | |||
|
|||
If a positive integer value is passed, it will loop that number of times. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably clean up the signature docs, specifically around this part:
EXPRESSION {KeyLookup Expression|Call Expression}: An expression that typically returns a list like data structure. If the value of the EXPRESSION is an observable list (for example: can-define/list/list), the resulting HTML is updated when the list changes. When a change in the list happens, only the minimum amount of DOM element changes occur. The list itself can also change, and a difference will be performed, which also will perform a minimal set of updates.
I think we should make it more clear what happens if the expression
evaluates to:
- An array-like structure (linking to canReflect.isListLike would be good here)
- An object-like (key-value) data structure
- A Number
Yeah, I think this is a great feature! I added notes for a few cleanup items. Thanks @James0x57 ! |
Hey fam!
This adds integer count loops to output based on numbers.
Most frequently for me I've needed this for heavy visual builds.
I queried about this years ago, wish I would have taken a look sooner since it was so easy to implement.
I understand if you decide against the feature, but I'd really like to have it and would be happy to discuss further if needed!
Hope you're all well!
//James