GithubHelp home page GithubHelp logo

Comments (7)

justinwoo avatar justinwoo commented on April 25, 2024

I think the only documentation is in the source code:

https://github.com/facebook/react/blob/8cb2812cff6a6cb54bb673254f1170281ce0790a/src/vendor/core/merge.js#L22

https://github.com/facebook/react/blob/8cb2812cff6a6cb54bb673254f1170281ce0790a/src/vendor/core/copyProperties.js#L20

tl;dr merge returns a fresh object merge of the operands, copyProperties mutates the hell out of the first operand and returns it.

from flux.

justin808 avatar justin808 commented on April 25, 2024

That makes sense why copyProperties must be called with "new".

Any reason TodoStore could not be created the same way? I dug into the code a bit and it seems like merge has some specific semantics regarding "merging" objects like arrays, whereas with copyProperties, the second object will overwrite the propery in the first object.

Anyway, this differece would be worth a comment in the code, or if there is no difference, then one technique should be picked.

from flux.

zpao avatar zpao commented on April 25, 2024

copyProperties has mostly been replaced by merge in new code, but there is still a decent amount of older code that hasn't been updated because it works. merge now being really just an alias for Object.assign means we may even deprecate those callers and just call it directly. Either way, yes one should be picked but the example app was written months ago and hasn't been updated much.

from flux.

justin808 avatar justin808 commented on April 25, 2024

@fisherwebdev @zpao A related question is this declaration in ThreadSection.react.js, line 21

function getStateFromStores() {
  return {
    threads: ThreadStore.getAllChrono(),
    currentThreadID: ThreadStore.getCurrentID(),
    unreadCount: UnreadThreadStore.getCount()
  };
}

I'm wondering if there was a reason that it was not declared like:

var getStateFromStores = function() {
....

from flux.

zpao avatar zpao commented on April 25, 2024

Because we wanted to. In general we prefer that style and it does have semantic differences in JS. Here's a deeper dive into the differences: http://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/. There are times where your latter example is appropriate.

from flux.

justin808 avatar justin808 commented on April 25, 2024

@zpao Very helpful article for a reforming CoffeeScripter-Rails-I-don't-use-modules-nor-Javascript developer! Do you have a link to any style guidelines, especially one that has some "whys"?

from flux.

zpao avatar zpao commented on April 25, 2024

https://github.com/airbnb/javascript is quite good from what I remember but it's been a while since I looked closely.

from flux.

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.