Comments (4)
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.
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.
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.
@idchlife I'm migrating this to developit/preact-www#7 since that's where the PRs will go.
from preact.
Related Issues (20)
- Type errors involving `forwardRef` and `Ref` in the compatibility layer. HOT 3
- Color of ix-icon-button HOT 1
- Starting from version 10.20 will cause the order of child elements to be reversed HOT 18
- `package.json#exports.browser` does not adhere to Node module type semantics HOT 3
- Preact is not working for tailwindcss & react-icons HOT 5
- [email protected] unexpected child ordering with skew based diff
- [email protected] application is broken on old user agents HOT 2
- syntax for choosing setting a property vs attribute on elements HOT 8
- useEffect never called HOT 2
- JSX prop works incorrectly on Custom Element, Preact fails to detect JS property setter HOT 5
- [preact/hooks] useMemo keeps recalculating even when the dependency is not changed HOT 2
- JSX type errors on React Bootstrap 2.x & Preact 10.x HOT 6
- Type inference of Omit type not working, CSSProperties in preact/compat HOT 3
- Options debounceRendering and requestAnimationFrame HOT 1
- Support cleanup functions for refs
- Suspense / ErrorBoundary content rendered twice when hydrating with render HOT 1
- Consider bumping version of `@preact/compat` to 18
- RFC: Hydration 2.0
- Aliasing in node refers to the old @preact/compat HOT 2
- Failed to execute insertBefore DOMException happens on rendering list of items HOT 2
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 preact.