Comments (7)
I don't know much about the compiler changes, but I think it was (is?) useful in this case:
<my-tag>
<div each={x in items}>
<p>{getCount()}</p>
</div>
this.count = 0
getCount() {
this.count += 1
return this.count
}
</my-tag>
getCount
gets called against the anonymous tag created by each
. Without the bind, we'd update count
on that anonymous tag, rather than my-tag.
from compiler.
If it's not too much of a pain, I'd agree that this should be consistent with javascript's normal hoisting behavior.
from compiler.
Looks easy to implement it. Just inserting the function on top, instead of bottom of parts
.
https://github.com/riot/compiler/blob/v2.5.3/lib/compiler.js#L413-L426
from compiler.
@cognitom you're right, It looks easy, this week...
EDIT: Of course, not so easy because https://github.com/riot/compiler/blob/v2.5.3/lib/compiler.js#L425
if (toes5 && !/^\s*.\s*bind\b/.test(js)) parts.push('.bind(this)')
...and the output for the test.
from compiler.
btw, I was thinking the other day about the functions generated by the riotjs
parser, ex. from:
func(){ blah }
to
this.func = function() { blah }.bind(this)
Is bind
neccesary in this case?
So it was in the original compiler so I kept it, but it seems redundant. In my code I've never had a need for bind
with functions declared that way as they are always called with the correct context.
@cognitom , @rogueg , If I'm not missing something maybe we can remove the bind
in tmpl v3.
from compiler.
@rogueg I see now, thanks.
from compiler.
closing this issue as clear SRP violation. The riot compiler will convert your components avoiding to touch your original javascript, if you need any special js preprocessor you can rely on registerPreprocessor
method
from compiler.
Related Issues (20)
- [BUG]the compile(4.0.0-beta.5) should handle empty style or script node
- when tag with a namespace is defined, inline styling is not working HOT 2
- Unwanted characters are inserted when escaping CSS strings HOT 4
- Behaviour of value attribute HOT 17
- v4.3.6 Didn't get published on npm repository HOT 2
- createValueExpression::sourceNode.expressions is undefined
- Cannot access object property within template, key is not defined HOT 1
- Value on custom tags should be always passed down as prop
- Parse error when use stylus as css preprocessor HOT 2
- After version 4.4.3 (v4.5.0) an error occurs: string.trimStart is not a function HOT 3
- Emit compiler warning, if riot script tag is outside of root tag HOT 1
- ImportExpressions are not supported
- Asynchronous preprocessor HOT 4
- Wrong compilation for in parentheses expression HOT 2
- "src" attribute for <style> and <script> HOT 5
- Multiline Sourcemap Issues HOT 2
- Importing scss inside of riot component HOT 4
- template element related: generated style has incorrect selector; elements of template does not receive is= tagname to be selected HOT 2
- Inline object declarations in tags fail to compile in RiotJS ver 6; works in RiotJS ver 5. HOT 2
- Boolean attributes rendering should be enabled on custom elements as well only for certain attributes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compiler.