Skip to content

Instantly share code, notes, and snippets.

@karolk
Last active June 7, 2018 10:34
Show Gist options
  • Save karolk/aaad6f8e7ab37f1dc2bfbae83e0d282a to your computer and use it in GitHub Desktop.
Save karolk/aaad6f8e7ab37f1dc2bfbae83e0d282a to your computer and use it in GitHub Desktop.
versions in prototype chain
// IDEA: start with an object using a symbol as a marker
const create = (obj, changeSet) => Object.assign(Object.create(obj || {[Symbol.for('versionstart')]: true}), changeSet);
const getPreviousState = obj => {
const maybePrev = Object.getPrototypeOf(obj);
if (!maybePrev || maybePrev[Symbol.for('versionstart')]) {
return null;
}
return maybePrev;
}
// TODO how do we know how many versions we have?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment