UNPKG

p5

Version:

[![npm version](https://badge.fury.io/js/p5.svg)](https://www.npmjs.com/package/p5)

36 lines (29 loc) 602 B
class States { #modified = {}; constructor(initialState) { for (const key in initialState) { this[key] = initialState[key]; } } setValue(key, value) { if (!(key in this.#modified)) { this.#modified[key] = this[key]; } this[key] = value; } getDiff() { const diff = this.#modified; this.#modified = {}; return diff; } getModified() { return this.#modified; } applyDiff(prevModified) { for (const key in this.#modified) { this[key] = this.#modified[key]; } this.#modified = prevModified; } } export { States };