Skip to content

Instantly share code, notes, and snippets.

@kring
Last active December 4, 2019 00:15
Show Gist options
  • Save kring/1daa3c43e78cc02118d7626d81e1463b to your computer and use it in GitHub Desktop.
Save kring/1daa3c43e78cc02118d7626d81e1463b to your computer and use it in GitHub Desktop.
import { observable, computed } from "mobx";
class LongLived {
@observable
foo = 5;
}
class ShortLived {
constructor(readonly longLived) {
this.longLived = longLived;
}
get bar() {
return this.longLived.foo * 2;
}
}
const longLived = new LongLived();
let sum = 0;
for (let i = 0; i < 100; ++i) {
const shortLived = new ShortLived(longLived);
sum += shortLived.bar;
}
console.log(sum);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment