1
0
Fork 0

🚧 Dedicated debug object

This commit is contained in:
Joost De Cock 2018-08-07 16:32:16 +02:00
parent ff9b561233
commit a357586344
2 changed files with 23 additions and 2 deletions

16
src/debug.js Normal file
View file

@ -0,0 +1,16 @@
import * as hooklib from "hooks";
function Debug(hooks) {
for (let k in hooklib) this[k] = hooklib[k];
this.hooks = hooks;
let self = this;
this.hooks.attach("debug", self);
return this;
}
/** Debug method, exposes debug hook */
Debug.prototype.debug = function(data) {};
export default Debug;

View file

@ -8,6 +8,7 @@ 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"; import Store from "./store";
import Debug from "./debug";
export default function Pattern(config = false) { export default function Pattern(config = false) {
// width and height properties // width and height properties
@ -67,7 +68,9 @@ Pattern.prototype.draft = function() {
}; };
/** Debug method, exposes debug hook */ /** Debug method, exposes debug hook */
Part.prototype.debug = function(data) {}; Pattern.prototype.debug = function(data) {
this.dbg.debug(data);
};
Pattern.prototype.render = function() { Pattern.prototype.render = function() {
this.svg = new Svg(this); this.svg = new Svg(this);
@ -83,7 +86,9 @@ Pattern.prototype.on = function(hook, method) {
}; };
Pattern.prototype.with = function(plugin) { Pattern.prototype.with = function(plugin) {
console.log(plugin); this.dbg = new Debug(this.hooks);
this.debug(`Plugin: ${plugin.name} v${plugin.version}`);
if (plugin.hooks) this.loadPluginHooks(plugin); if (plugin.hooks) this.loadPluginHooks(plugin);
if (plugin.macros) this.loadPluginMacros(plugin); if (plugin.macros) this.loadPluginMacros(plugin);