intercellular / cell

A self-driving web app framework
https://www.celljs.org
MIT License
1.51k stars 94 forks source link

Genotype snapshot feature #144

Open gliechtenstein opened 7 years ago

gliechtenstein commented 7 years ago

Cell attaches a data structure called Genotype to each node to allow each node to manage its own state in a decentralized manner.

So if you take any node created by Cell, and query its Genotype you'll get the "blueprint" of the node. For example you create a node like this:

c = {
  $cell: true,
  id: "item",
  $text: "Hello world",
  _update(message) {
    this.$text = message;
  }
}

and query it like this:

console.log(document.querySelector("#item").Genotype)

This is pretty useful for debugging since the Genotype object updates in realtime to keep the state of each node.

However, there's a limitation to the current implementation. Currently Cell wraps all the functions with Nucleus.bind() to make sure each time a function is called it gets added to the Nucleus._queue and the diff logic is triggered when the call stack becomes empty.

This means when I do something like

console.log(document.querySelector("#item").Genotype._update)

it will print the wrapper function that's returned by Nucleus.bind(), not the original function.

Need to find a way to retrieve each function's original form instead of the bound function so it's completely stateless and reusable.

gliechtenstein commented 7 years ago

So far have gotten this far https://github.com/intercellular/cell/pull/145

It works, but gonna try to sleep on this and see if it feels right in terms of naming, API, and the overall way it works.