Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

store.data as immutable data structure #55

Open
sobrinho opened this issue Nov 10, 2016 · 2 comments
Open

store.data as immutable data structure #55

sobrinho opened this issue Nov 10, 2016 · 2 comments

Comments

@sobrinho
Copy link
Member

I know we are almost against dependencies but I believe this one worth the discussion (maybe immutable.js?).

As we spoke and tried to do a couple times, the data property would be better as a immutable structure, so, assigning a new attribute would make a entire new copy, like this:

let store = new ObjectStore;
let x = store.data;

store.setAttribute("name", "John");

let y = store.data;

console.log(x === y); // => false

That would allow us to avoid things like lastGeneratedJSON machinery as we can just pass the data property as the result of toJSON, #46 machinery as we can just keep a copy of the data property and compare latter as the above example and even the machinery to keep nested objects with their own object ids.

But the winner here would be components with a just oldProps !== newProps compare to re-render the entire component tree.

Do you think worth the research to make something like that?

I'm not against we building our own embed immutable library to avoid the immutable.js but that path may be tough, we can just assume that data would be immutable and work on that.

@sobrinho
Copy link
Member Author

Pseudo-code:

setAttribute (attribute, value) {
  if (this.data[attribute] === value) {
    return false;
  }

  let data = deepClone(this.data);
  data[attribute] = value;

  this.data = data;

  return true;
}

@sobrinho
Copy link
Member Author

Just thoughts to remember to research:

How we would deal with nested stores as the data property would be a immutable instance?

Not sure if we could rip the toJSON output machinery.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant