Code Monkey home page Code Monkey logo

Comments (4)

developit avatar developit commented on July 20, 2024

True, I guess that avoids the external dependency. I like the @bind syntax for performance reasons (the bound method is more easily garbage collected), but for demos it is unnecessary.

Do you think the class property syntax for methods will be understandable for people? I guess we could add a note with a link to an explanation if need be.

from preact.

idchlife avatar idchlife commented on July 20, 2024

Personally I find it more attractive and people should use it too. It's on stage-1 as far as I know.

What is your opinion about GC with this code transpiled? https://goo.gl/Dux8xW

If everything is ok with it - I think we should insist on using this syntax so we would teach newcomers more about es2015-2016

And propose linkState as not salvation from bind problem but as useful tool, which helps binding without addChangeListener etc or activating something via actions.

from preact.

developit avatar developit commented on July 20, 2024

My GC comment was mostly about the transpiled code (creating a closure within the constructor) - I'm not knowledgable enough about the 2016 spec to know if the actual implementation in engines would be significantly different.

On one hand its nice because you use a single shared closure to scope the context for N arrow functions (ideal). On the other hand, while Function.prototype.bind() has worse runtime performance than creating a closure, it pushes the problem into the JS engine, which will always get faster over time. Since .bind() internally creates functions that are not quite the same as regular JS functions (like a lightweight proxy), I've always pictured the internal implementation being something like a Weak Map (I may be wrong on this?), which is more easily garbage collected than a closure.

That said, since my reasons for liking @bind are mainly style and opinion, I don't want to force that on anyone. We can certainly start switching the examples over to use class property arrows in place of @bind(). Perhaps I'll even take to doing it in my own work ;)

As for linkState(), I'd like to reword some of the documentation to be more along those lines - it's a way to create event handlers declaratively, anything else is basically sugar.

Cheers

from preact.

developit avatar developit commented on July 20, 2024

@idchlife I'm migrating this to developit/preact-www#7 since that's where the PRs will go.

from preact.

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.