Code Monkey home page Code Monkey logo

Comments (12)

vbfox avatar vbfox commented on July 19, 2024 3

Ok i'll do a PR changing the current signature

Move fast break things is one of the Facebook motto after all and they make React :)

from fable-react.

vbfox avatar vbfox commented on July 19, 2024 3

memo would take the JS function name.

For anonymous functions F# doesn't support naming them.

For normal ones Fable use name mangling so the name wouldnot be good.

So in the end I preferred forcing a name to be provided.

from fable-react.

vbfox avatar vbfox commented on July 19, 2024 1

One of the potential way to sidestep the problem would be to provide a more explicit name like memoBuilder, createMemoBuilder, ... something that echo the fact that the result should be saved & not used directly

from fable-react.

MangelMaxime avatar MangelMaxime commented on July 19, 2024 1

Ah ok I see.

I guess if we educate correctly the person and show your minimal example as a doc comment of memoBuilder it should be fine.

Like that people can copy/paste the minimal example code and adapt it directly to their code.

from fable-react.

MangelMaxime avatar MangelMaxime commented on July 19, 2024 1

Ahah I guess that the comment explanation is ok as @alfonsogarciacaro and me answered the same thing at the same time :D

from fable-react.

vbfox avatar vbfox commented on July 19, 2024 1

let memo = memoBuilder 😁

from fable-react.

MangelMaxime avatar MangelMaxime commented on July 19, 2024

I am not sure to understand the benefit of simpleMemo ...

from fable-react.

alfonsogarciacaro avatar alfonsogarciacaro commented on July 19, 2024

I guess the benefit is you don't need to use ofElementType:

ofElementType helloWorldComponent { Name = name } []
// vs
hello { Name = "World" }

But if it makes it easier to write cases where you lose the optimization I'd say we should keep only the API that leads user into the pit of success (you said that 😉). I'm a bit concerned than on one hand we're promoting the simplicity of Elmish and on the other users need to remember all the pitfalls of React. Savvy users can have a prelude with this kind of helpers for their projects 👍

from fable-react.

vbfox avatar vbfox commented on July 19, 2024

You start from :

let hello name =
	span [] [str "Hello, "; str name]

let view model =
	hello model.Name

Now you saw my talk and want to add components & get better perf :

type HelloProps = { Name: string }
let helloComponent = memo "Hello" <| fun { Name = name } ->
	span [] [str "Hello, "; str name]

let hello p = ofComponentType helloComponent p []

let view model =
	hello { Name = model.Name }

But what i'm proposing is to remove the temporary helloComponent (That is always annoying to find a name for) :

type HelloProps = { Name: string }
let hello = simpleMemo "Hello" <| fun { Name = name } ->
	span [] [str "Hello, "; str name]

let view model =
	hello { Name = model.Name }

from fable-react.

vbfox avatar vbfox commented on July 19, 2024

Ah one of the other things to consider is that while it break memo optimizations it's pretty harmless... it ends up acting like ofFunction so it's not much of a problem

Also the name memo (even "simple") is not something you might use accidentally so reading the function help might be something people would already do

from fable-react.

alfonsogarciacaro avatar alfonsogarciacaro commented on July 19, 2024

Hmm, memoBuilder with explanation in the comment would work. But I'd be in favor to keep only one API (even if I already released a version with memo) so users don't need to choose among many options and can just follow examples.

from fable-react.

cmeeren avatar cmeeren commented on July 19, 2024

Why does memoBuilder need a string name but memo does not?

from fable-react.

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.