✨ Added store
This commit is contained in:
parent
fd80450d77
commit
718c9acda5
3 changed files with 24 additions and 3 deletions
|
@ -7,6 +7,7 @@ import snippet from "./snippet";
|
||||||
import svg from "./svg";
|
import svg from "./svg";
|
||||||
import hooks from "./hooks";
|
import hooks from "./hooks";
|
||||||
import pack from "bin-pack";
|
import pack from "bin-pack";
|
||||||
|
import store from "./store";
|
||||||
|
|
||||||
export default function pattern(config = false) {
|
export default function pattern(config = false) {
|
||||||
// width and height properties
|
// width and height properties
|
||||||
|
@ -20,7 +21,7 @@ export default function pattern(config = false) {
|
||||||
// Data containers
|
// Data containers
|
||||||
this.settings = {};
|
this.settings = {};
|
||||||
this.options = {};
|
this.options = {};
|
||||||
this.store = {};
|
this.store = new store();
|
||||||
this.parts = {};
|
this.parts = {};
|
||||||
|
|
||||||
// Merge config with defaults
|
// Merge config with defaults
|
||||||
|
@ -49,7 +50,7 @@ export default function pattern(config = false) {
|
||||||
config: this.config,
|
config: this.config,
|
||||||
settings: this.settings,
|
settings: this.settings,
|
||||||
options: this.options,
|
options: this.options,
|
||||||
values: this.values
|
store: this.store
|
||||||
};
|
};
|
||||||
this.part.prototype.context = this.context;
|
this.part.prototype.context = this.context;
|
||||||
this.part.prototype.macros = {};
|
this.part.prototype.macros = {};
|
||||||
|
|
20
src/store.js
Normal file
20
src/store.js
Normal file
|
@ -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;
|
|
@ -73,7 +73,7 @@ export function shorthand(part) {
|
||||||
sa: part.context.settings.sa || 0,
|
sa: part.context.settings.sa || 0,
|
||||||
measurements: part.context.settings.measurements || {},
|
measurements: part.context.settings.measurements || {},
|
||||||
options: part.context.options || {},
|
options: part.context.options || {},
|
||||||
values: part.context.values || {},
|
store: part.context.store,
|
||||||
points: part.points || {},
|
points: part.points || {},
|
||||||
paths: part.paths || {},
|
paths: part.paths || {},
|
||||||
snippets: part.snippets || {},
|
snippets: part.snippets || {},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue