Open yoshuawuyts opened 7 years ago
Whoa sounds neat. Any examples of this somewhere?
@bcomnes not yet, but this is the gist I think:
// Each application gets a global clock that's updated on each "render" call to
// the current value of the unix timestamp (e.g. Date.now())
var state = {
clock: Date.now(), // generated by window.performance.now() or Date.now()
items: [ ]
}
// Whenever a value is created, we associate the current value of "clock" with
// it
state.items.push({
id: 1,
first: 'hello',
second: 'world',
timestamp: state.clock
})
state.items.push({
id: 2,
first: 'hello',
second: 'planet',
timestamp: state.clock
})
// Whenever emitter.emit('render') is called, we update the clock
state.clock = Date.now()
// Whenever an item is updated, we modify the timestamp
state.items[0] = {
id: 1,
first: 'hello',
second: 'saturn',
timestamp: state.clock
}
// Determining if data has changed now becomes constant time, is less prone to
// errors and decoupled from the shape of the data itself.
component.on('update', function (props) {
return this.props.timestamp < props.timestamp
})