HNHacker News
TopNewBestAskShowJobs

mlsarecmg

464 karma · joined May 7, 2016

submissionscomments
mlsarecmg··on Show HN: Three and React = react-three-fiber, a new renderer based on Fiber
You would use them as you always did. You have raw access to everything. But if you want loading results to be managed, put them into useEffect/useMemo and render out the results. For instance i've just made a text-sprite component that looks like this:

    function Text({ children, ...props }) {
      const { camera, size, viewport } = useThree()
      const { width } = viewport()
      const canvas = useMemo(() => {
        const canvas = document.createElement('canvas')
        canvas.width = canvas.height = size.width * 2
        const context = canvas.getContext('2d')
        context.font = `bold ${size.width *
          0.45}px -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif`
        context.textAlign = 'center'
        context.fillStyle = 'black'
        context.fillText(children, size.width, size.height + size.width * 0.4)
        return canvas
      }, [children, size.width])
      return (
        <sprite scale={[width, width]} {...props}>
          <spriteMaterial name="material">
            <canvasTexture name="map" image={canvas} premultiplyAlpha onUpdate={s => (s.needsUpdate = true)} />
          </spriteMaterial>
        </sprite>
      )
    }
mlsarecmg··on Show HN: Three and React = react-three-fiber, a new renderer based on Fiber
Would help in the same way that react-dom helps the dom, especially performance. React basically manages the scene, only updating the parts that change. As for processor speed, React only mounts/unmounts, it maintains THREEs performance otherwise. In the demo for instance there are two animations, the stars are driven by the render loop (outside of react) and the thing in the middle using react-spring, which also animates outside of react.

I think the performance increase for a large project with a complex scene graph could be drastic compared to handling it manually - just like vanilla js would not easily get even with react unless you implement change detection, read/write queues, etc. With react-fibers scheduling the difference will only get larger since now it can bail out of or defer actions that would blow the 60fps frame budget.

As for memory and immutability, the actual v-dom tree is next to nothing, a node is a couple of bytes. This is the same as for a huge dom UI app with millions of divs and spans and table fields. The logical tree never hurts. One big problem with THREE has always been garbage and the object overhead - it's super easy to create leaks or create objects needlessly

    mesh.position.copy(xyz.clone())
I've been doing three for a couple of years now and to not be wasteful takes a lot of discipline as basically everything nudges you into re-creating objects since re-use can have unexpected side-effects. With the reconciler you can stow away objects into the graph, which means they're managed. Probably will reduce the memory footprint in the end, even with a v-dom on top.
mlsarecmg··on I love React Hooks
JSX is a dsl, like typescript or flow, it doesn’t change or affect your code, all assumptions stand, it doesn’t break scope. Vue templates are not a dsl, they break all assumptions and your scope. There is no difference between Vue and angular in that regard, both could not do this with templates:

    const A = () => <div />
    const B = () => <A />
JSX turns that into:

    const A = () => createElement('div')
    const B = () => createElement(A)
That is all that JSX does. Vue on the otherhand parses its own language, breaks scope, separates concerns that shouldn’t be separated and in the end joins them via dependency injection again. We’ve been through this years before Vue existed with angular and others.

BTW, your info is outdated. "class" is allowed in React as of V16.

mlsarecmg··on Making SetInterval Declarative with React Hooks
Hocs had several problems, they couldn't access context, re-using one result in another is hard, they create a new component for every thing you want to do, etc.

Take this example for instance: https://codesandbox.io/embed/26mjowzpr

It measures out the view, reads out media queries, uses the results to construct a grid, uses a hook to turn it into an animatable, and just spits out the view as if nothing happened. All of this in the same component, with small, re-usable utility functions tapping into the host-components lifecycles. Just by looking at it you know what it's doing.

This is how a component should behave from now on, an entity that hooks into the host, instead of a class the host calls into. In my experience this is the first time you can express logic linearly: x > y > z > view, without wraps, inversion of control and DI.

Now imagine doing this with hocs ... even stacking two is already destroying any hope of guessing what's going on.

mlsarecmg··on Show HN: Learn React fundamentals
Here's something that Swizec Teller wrote after having to use it on a project: https://medium.com/@swizec/some-thoughts-on-vue-after-deploy...

In essence, many things you take for granted do become harder because Vue is modelled after older templating frameworks like Angular, so you're jumping right into DI again and scope separation. It makes it less flexible and simple compared to React. My biggest gripe with it was that for many problems the basic knowledge you have isn't enough, you need Vue-specific solutions (remember the "Angular-way"?). After a while it gets easier.

mlsarecmg··on Show HN: Learn React fundamentals
You style components in React like you always did before. That's the whole thing about it, it never changes what you know. ... Unless you decide using a more modern approach like styled-components et al.
mlsarecmg··on Introducing Hooks
Nah, this has nothing to do with that. If you pass an anonymous fn to a pure-component its shouldComponentUpdate part flags it for re-rendering since the property is new every time, which can be a problem depending on how large its payload is.

Creating a function costs you a few clock ticks, there is no bottleneck, rendering a component and its entire sub tree for no reason on the other hand can be critical.

mlsarecmg··on Plans for the Next Iteration of Vue.js
This one was pretty good and goes into deeper details instead of just claiming x is better than y: https://medium.com/@swizec/some-thoughts-on-vue-after-deploy...

The fundamental difference between React and Vue is vision. React bets on functional programming and moves closer to reaching its goal, perhaps shedding the last OOP parts some day.

Vue follows an older paradigm, Angulars basically, but with React underpinnings. It's heavily inspired by OO templating, pseudo code mixed into html. Perhaps the gravest difference if you come from React is that it encourages mutation, to an extent that now forces it to maintain two incompatible versions going forward due to IE11's lack of proxies.

mlsarecmg··on Vue Native
Well i give you that, css is what it is, but even with basic css knowledge, making a dropdown appear anywhere you want is not hard: https://codesandbox.io/embed/w7499vxrzk

It could be better, but it's even got a proper grid system now, close to wpf's. From what i remember though, wpf's styles also had some rough spots.

mlsarecmg··on Vue Native
Xaml and Wpf? Qt? I am honestly asking you, have you worked with React before? XAML has a learning curve of 2 years and more to get to expert level. I developed with it for more or less 5 years and i still have nightmares. Qt and the others are all imperative layout inflaters. React was a revolution, maybe the first cross platform paradigm that actually made sense. A learning curve that doesn't span more than a day. In all my years as a frontend developer i haven't seen a simpler way to create user interfaces. And sure as hell i would prefer React on the desktop or mobile over aged native toolkits that still struggle with obsolete oop-mvc-templating semantics, especially wpf and xaml, which in my opinion where the sole reason why i started hating my job.
mlsarecmg··on Why Is Front-End Development So Unstable?
The view and the presentational code that builds it are one, they belong to the same presentational layer and always have been. To artificially separate them was a major mistake of the old paradigm. Older approaches, like Knockout, Angular, Vue, etc., have to support presentational code as well, and obviously it is mixed into your html, but in a way that is severely limited and causes complications. Think of it, to be able to do your v-if, v-for, v-else, etc. an entire templating language had to be built, your view isn't part of the scope that that can access the data-model, so dependency injection had to be utilized, components in that model aren't components but directives that have to be registered to re-use one another. The complexity is actually mind-boggling.

These are the exact reasons why React came about - it removes that complexity entirely. It is tiring having to learn frameworks and arbitrary extensions, googling for framework-specific solutions for every trouble that surfaces.

mlsarecmg··on Proton Native – React Native for the desktop
It just doesn't look comparable to the example i've posted. They were really, really simple, so if QT is the same, i would love to see it do the same. As for imperative registration, didn't you just link me to it? If they were functions, you could do:

    const A = () => <div>...</div>
    const B = () => <h1><A /></h1>
Notice that the B component can refer to the A component because it's in the same scope. There's no magic and no binding/loading. A is a function that is called inside B's function body. It also isn't done by inference of an ID (which would be registration).
mlsarecmg··on Proton Native – React Native for the desktop
And that is what i suspected and what i've seen in all examples i have browsed through so far. The enabled prop wasn't the point, it demonstrates functional composition. All of the above uses old, traditional layout inflating, dependency injection, imperative registration for re-using components, ...and common MVC. They are hard for applications that get even slightly complex.

There is a major difference between that and Reacts approach.

mlsarecmg··on Proton Native – React Native for the desktop
From what i've seen this is layout inflating, you have a template and you fill it imperatively. Which would be one of the oldest paradigms we have. Maybe i am getting this completely wrong, forgive me in that case, but in all examples i've seen so far it's like that.

Could you please paste an example of a real, functional QT component? For instance a component that is re-used in another component,

    const A = ({ text }) => <div>{text}</div>
    const B = () => <A text="hello" />

    <B /> // -> <div>hello</div>
as well as functional composition (higher-order-components):

    const canBeDisabled = Component => props => props.disabled ? null : <Component {...props} />
    const ComposedB = canBeDisabled(B)

    <ComposedB /> // -> <div>hello</div>
    <ComposedB disabled /> // -> null
an example for statefull components would also be nice:

    class C extends Component {
        state = { count: 0 }
        up = () => this.setState(state => ({ count: state.count + 1 })
        render() {
            return <div onClick={this.up}>{this.state.count}</div>
        }
    }

    <C /> // -> <div>0</div>, clicks count up reactively
mlsarecmg··on Proton Native – React Native for the desktop
This seems like a misunderstanding of what React is. JSX is not a template. It is a DSL or superset with direct access to the presentational layer. It gets "transpiled" away in the building phase. React components are not imperative but declarative, they reflect state instead of inflating layout. Layout inflating (QT, Android), MVC/MVVM (XAML), and views being functions of state (React) are paradigm changes.

View = fn(state) solves longstanding issues with all the previous approaches, and of course it decreases their complexity. It is also the first approach that's breaching the platform barrier successfully while maintaining the high-level. You can write React for countless of targets, being able to re-use and apply the eco-system.

mlsarecmg··on Proton Native – React Native for the desktop
XAML is a template, JSX is a DSL. A template kills scope, duplicates coding semantics, messes up app flow with bindings and needs dependency injection to get local scope back - all of this has been solved with JSX, which now pretty much fulfills Silverlights dream: https://news.ycombinator.com/item?id=16198843

The crazy part is, that you can share code and eco-system components among these targets, no matter if they're native or otherwise. Here's a shell applications for instance that uses react-motion to shift stuff around: https://github.com/gaearon/react-blessed-hot-motion

Microsoft seems heavily invested in it as well (react-windows, reactXP, UI-fabric, ...).

mlsarecmg··on Proton Native – React Native for the desktop
The transpiler is a build build (a babel plugin), it isn't even a part of the application nor does it run while loading. The snippet above turns into a bunch of nested functions.
mlsarecmg··on Proton Native – React Native for the desktop
JSX gets transpiled, not parsed. The effort is completely on the tooling side, there's no loading effort that changes JSX into functions. The main difference between your two snippets is that one is declarative and the other is imperative. The declarative piece can reflect state and react to changes, the other can't - you do that manually.
mlsarecmg··on Learn React by building a web app
Web components are a regression, though. There's nothing in the slightest that would make interop possible. They just wrap a shadow root, and within you are greeted with a naked dom again, which calls for a framework to drive it.

Imagine for every 10 components you pull you'd load 10 separate frameworks - unless they all come from the same source. These "components" wouldn't be able to know one another or work together at all. The only thing web components are good for are encapsulated styles, but that hasn't been a problem for many years now.

Since they've come up with the idea the web has moved on. React has progressed to such an extent that javascript has effectively left the browser, drives full-native applications, renders on the server, makes interop possible that no piece of technology has been able to pull off before, where you can share code and semantics on pretty much every platform while being able to re-use eco system components: https://news.ycombinator.com/item?id=16198843 and https://github.com/gaearon/react-blessed-hot-motion

Throwing all this away, we'd be back in a browser-tied web driven by dumb-components, and for no reason at all.

mlsarecmg··on Stimulus: A modest JavaScript framework for the HTML you already have
I think you're confusing something. You don't "build" dependencies, you consume them as pre-built modules.

As a package author you use whatever you want (rollup, webpack, gulp, grunt, ...), but you will most likely publish to npm, because bower is dead.

As a consumer you use npm or yarn, it doesn't matter, and a tool that handles modules, probably webpack. Even if you'd use something else (rollup & parcel come to mind), it doesn't matter, they will all treat your dependency the same.

EDIT: Yeah i just saw you're referring to Polymer. I take it back, everything you said applies. But then again, people probably want to suffer when they use it. Though very few actually do use it. I just don't think it's a good example to make to describe web dev in general. Rather Google was the only one that missed the train it seems, they worked in the opposite direction.

mlsarecmg··on React Native and Yoga Both Given MIT Licence by Facebook
You mean, you do that? I don't get it otherwise.

http://www.npmtrends.com/react-native-vs-weex-toolkit

Native is hard, React needed years to get it even nearly right, and it did that with the community's backing. At this point RN features dozens of renderers outside of the mobile space, with some of them made by the very vendors that sell their platforms (for instance Microsofts react-native-windows).

A couple of them here: https://pbs.twimg.com/media/DUF19IlXcAE2UC6.jpg:large

Can't imagine why anyone would willingly want to wait another 4-5 years until Weex is where RN is today.

mlsarecmg··on Rollup now has code-splitting and we need your help
This is how we are doing it in webpack, i think rollup can alias as well:

webpack.config.js

    alias: {
        three$: path.resolve('./three.js')
    }
and a local copy of three.js

    // Only export the things that are actually needed, cut out everything else

    export { WebGLRenderer } from 'three/src/renderers/WebGLRenderer.js';
    export { ShaderLib } from 'three/src/renderers/shaders/ShaderLib.js';
    export { UniformsLib } from 'three/src/renderers/shaders/UniformsLib.js';
    ...
mlsarecmg··on Guide to JavaScript Frameworks

    const { for, class } = this.props
Will crash. It's just a bit inconvenient (and inconsistent for beginners) having to write:

    const { for: forHtml, class: className } = this.props
Some react-like libs do allow it, but the dom api takes offcial precedence, so it's all fine. It's just that HTML in general was made without taking all the things into account we demand of it today. It wasn't even made for imperative inflating, so the dom-api faced the same troubles.
mlsarecmg··on 3,500 Occult Manuscripts Will Be Digitized and Made Freely Available Online
Actually many traditions have had circles that retain and sublimate the seed, very interesting topic. See more here: https://gist.githubusercontent.com/drcmda/84456b58765cf83144...
mlsarecmg··on Guide to JavaScript Frameworks
> If it was just html I could write <label for=""> and not <label htmlFor="">, I could write <div class=""> instead of <div className="">

for and class are reserved statements, hence htmlFor and className are the official api names, in other words they belong to the actual web-api spec, there's nothing arbitrary about it:

https://developer.mozilla.org/en-US/docs/Web/API/Element/cla...

https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelEl...

If you really dislike it, you can still use class and for: https://github.com/insin/babel-plugin-react-html-attrs

> or I would be able to write a simple if-else statement

{} evaluates to a ternary. You can use if, according to the spec that's what do expressions are there for.

    do {
        if (condition) <div>yes</div>
        else <h>nope</h>
    }
Though most would probably prefer the following for stylistic reasons:

    condition 
        ? <div>yes</div> 
        : <h>nope</h>
> because those subtle differences can cost you hours of looking for mistakes

These two things are explained in a single sentence, every tutorial eases you into it, the first thing that comes up once JSX is mentioned.

mlsarecmg··on Guide to JavaScript Frameworks
Not just mobile apps:

Windows: https://github.com/Microsoft/react-native-windows

Macos: https://github.com/ptmt/react-native-macos

Linux (Qt): https://github.com/status-im/react-native-desktop

AR: https://github.com/HippoAR/react-native-arkit

VR: https://facebook.github.io/react-vr/

TV: https://github.com/react-tv/react-tv

Shell consoles: https://github.com/Yomguithereal/react-blessed

Word: https://github.com/nitin42/redocx

Pdf: https://github.com/diegomura/react-pdf

3d: https://github.com/Izzimach/react-three

Sketchapp: http://airbnb.io/react-sketchapp/

Keynote: https://twitter.com/nishb1/status/913744410537537536

Hardware: https://github.com/iamdustan/react-hardware

Samplers: https://twitter.com/GabeRicard/status/911989894267973633

And so on ...

Finally being able to transfer knowledge and code, and due to the generic nature of React in some cases even everyday eco-system packages can be applied. For instance: https://github.com/gaearon/react-blessed-hot-motion (native console app using plain react-motion to move stuff around).

mlsarecmg··on Guide to JavaScript Frameworks
The points you've listed are the very reasons why i would prefer React actually ...

- JSX fixed all the templating issues from 10 years ago, i see no reason to go back to dependency injection, scope loss, arbitrary code-in-html expression and a semi-javascript accent

- Presentational view logic belongs to the controller while business logic is elegantly abstracted in React: view=fn(state). There's no point in ripping view creation from the presentational layer.

- Context and higher order components. Can't have those in an imperative architecture.

- v-for is not sane to me. Also odd, being forced to mix-in extensions for the simplest basics that go beyond the few presets Vue provieds: https://github.com/Krizzu/vue-for-range A React user doesn't solve problems by searching the internet for framework specific solutions, they import _ from 'lodash' and use _.range, like everyone else does.

- {condition && <div>hello javascript</div>}

- We have suffered through two-way data bindings with Angular already

- Vuex is not native. It mutates state by aggressively transforming state into setter/getters, with nasty edge-cases. Once Vue switches to version 3 using proxies, you'll maintain two incompatible codebases. React has Mobx, even though Redux is great. Also lots of lean and promising alternatives like Unistore.

- Knowing React you don't rely on documentation (though official docs are on point). It is simple enough to grasp it after looking at a view examples once. The api surface and cognitive overhead of React is a tiny fraction of Vues. Coming from Angular it is amazing that one month of learning and half a year of consulting docs turned into a week and a couple of months consulting with Vue. Yet, you can learn React fully in the shortest amount of time while simply remembering the few things you'd need to know. A generic round-trip, for instance the one at egghead, costs you 60 minutes total.

- http://www.npmtrends.com/angular-vs-react-vs-vue-vs-@angular...

mlsarecmg··on 2017 JavaScript Rising Stars
Honestly that is like saying Windows Phone doesn't need the apps.

React has a self sufficient cross platform eco system. I don't think people using primarily web frameworks even realize the implications of that yet. React works outside of the browser, and not just natively on mobile but literally everywhere. Imagine you use React as you always would to make a native command line application (https://github.com/Yomguithereal/react-blessed), but now you want to have a store or move things around, so you `npm install react-redux react-motion` and you just apply it (https://github.com/gaearon/react-blessed-hot-motion). Look at the code and try to picture the overhead if you had to do this in C++.

Being able to transfer code and knowledge, and seeing new renderers pop up for the wildest platforms each day, as well as official renderers made by big vendors (https://github.com/Microsoft/react-native-windows), the idea of a web-bound Angular-like framework seems odd in 2018. I wouldn't expect Vue to get the same kind of popularity without at least competing or doing something new.

mlsarecmg··on 2017 JavaScript Rising Stars
Github and Npm are both used in China all the same. I don't know about firewall restrictions, many chinese companies publish directly on Github. React is the most used in China in polls as well (stateofJS), with some of the biggest names and websites using it. If China would be excluded in these stats, that would impact Reacts outlook more for sure, any exception one could make would directly affect React in the same way.

As it stands npms numbers coincide with all the other sources you could pull: projects on github, tracked project dependencies, size of eco system, job market, etc.

mlsarecmg··on 2017 JavaScript Rising Stars
See it in context. The fastest growing framework on npm right now for instance is Preact (as per official report posted by Lauri Voss last week), but Preacts userbase is so small that it could grow hundredfold with insane growth rates percentually without scratching a competitor. That also applies to Vue. React gets more users in a week than Vue in its entire lifespan.

Go 2 years back on that page and you see a clearer picture, yes it did grow, but relatively contained compared to its competitors, specifically React.

And is it any wonder to anyone? I really ask myself. Would you go back to a stryingly typed templating framework with a complex api and ever changing ruleset, reliant on dependency injection and all the other stuff we went through with Angular? I don't think anyone would. It rather looks like Vue is catching the last remaining Angular 1.x refugees, but there isn't an ever increasing supply of those.

← PreviousPage 3 of 7Next →