diff --git a/src/pattern.js b/src/pattern.js index 4dbad6644cf..351d1f3f137 100644 --- a/src/pattern.js +++ b/src/pattern.js @@ -7,6 +7,7 @@ import snippet from "./snippet"; import svg from "./svg"; import hooks from "./hooks"; import pack from "bin-pack"; +import store from "./store"; export default function pattern(config = false) { // width and height properties @@ -20,7 +21,7 @@ export default function pattern(config = false) { // Data containers this.settings = {}; this.options = {}; - this.store = {}; + this.store = new store(); this.parts = {}; // Merge config with defaults @@ -49,7 +50,7 @@ export default function pattern(config = false) { config: this.config, settings: this.settings, options: this.options, - values: this.values + store: this.store }; this.part.prototype.context = this.context; this.part.prototype.macros = {}; diff --git a/src/store.js b/src/store.js new file mode 100644 index 00000000000..bb86c5a08e5 --- /dev/null +++ b/src/store.js @@ -0,0 +1,20 @@ +function store() { + this.data = new Map(); +} + +/** Sets a value under index key */ +store.prototype.set = function(key, value) { + this.data.set(key, value); +}; + +/** Sets a value under index key */ +store.prototype.setIfUnset = function(key, value) { + if (!this.data.has(key)) this.data.set(key, value); +}; + +/** Gets a value under index key */ +store.prototype.get = function(key) { + return this.data.get(key); +}; + +export default store; diff --git a/src/utils.js b/src/utils.js index 106af9462d7..6bcb7e525e5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -73,7 +73,7 @@ export function shorthand(part) { sa: part.context.settings.sa || 0, measurements: part.context.settings.measurements || {}, options: part.context.options || {}, - values: part.context.values || {}, + store: part.context.store, points: part.points || {}, paths: part.paths || {}, snippets: part.snippets || {},