From 583abb0236be2a2ede4d751d8db18222f2e44e32 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sat, 11 Jul 2020 18:04:29 +0200 Subject: [PATCH] feat(core): Added support for raising events --- packages/core/src/part.js | 4 +++- packages/core/src/pattern.js | 27 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/core/src/part.js b/packages/core/src/part.js index 1cd917a8394..8423ac26c15 100644 --- a/packages/core/src/part.js +++ b/packages/core/src/part.js @@ -184,7 +184,9 @@ Part.prototype.shorthand = function () { Path: this.Path, Snippet: this.Snippet, complete, - paperless + paperless, + events: this.context.events, + raise: this.context.events.raise } } diff --git a/packages/core/src/pattern.js b/packages/core/src/pattern.js index b031f2deefb..6301ac15b5f 100644 --- a/packages/core/src/pattern.js +++ b/packages/core/src/pattern.js @@ -23,6 +23,25 @@ export default function Pattern(config = { options: {} }) { this.Snippet = Snippet // Snippet constructor this.Attributes = Attributes // Attributes constructor + // Store events + this.events = { + info: [], + warning: [], + error: [] + } + const events = this.events + this.events.raise = { + event: function (data) { + events.info.push(data) + }, + warning: function (data) { + events.warning.push(data) + }, + error: function (data) { + events.error.push(data) + } + } + // Default settings this.settings = { complete: true, @@ -65,7 +84,8 @@ export default function Pattern(config = { options: {} }) { config: this.config, settings: this.settings, store: this.store, - macros: this.macros + macros: this.macros, + events: this.events } // Part closure @@ -554,6 +574,11 @@ Pattern.prototype.getRenderProps = function () { props.width = this.width props.height = this.height props.settings = this.settings + props.events = { + info: this.events.info, + warning: this.events.warning, + error: this.events.error + } props.parts = {} for (let p in this.parts) { if (this.parts[p].render) {