Code Monkey home page Code Monkey logo

Comments (7)

rogueg avatar rogueg commented on September 28, 2024 1

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.

andyfleming avatar andyfleming commented on September 28, 2024

If it's not too much of a pain, I'd agree that this should be consistent with javascript's normal hoisting behavior.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function#Function_declaration_hoisting

from compiler.

cognitom avatar cognitom commented on September 28, 2024

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.

aMarCruz avatar aMarCruz commented on September 28, 2024

@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.

aMarCruz avatar aMarCruz commented on September 28, 2024

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.

aMarCruz avatar aMarCruz commented on September 28, 2024

@rogueg I see now, thanks.

from compiler.

GianlucaGuarini avatar GianlucaGuarini commented on September 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.