From 2d76de59064cc7b28501eafedd7904f59cf26854 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Fri, 1 Jul 2022 10:56:31 +0200 Subject: [PATCH] log helpers --- packages/core/pattern.mjs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index f5c7cd512..5856a4fcd 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -1053,6 +1053,22 @@ export class Pattern { onTrigger(onTrigger) { return this._withHap((hap) => hap.setContext({ ...hap.context, onTrigger })); } + log(func = id) { + return this._withHap((hap) => + hap.setContext({ + ...hap.context, + onTrigger: (...args) => { + if (hap.context.onTrigger) { + hap.context.onTrigger(...args); + } + console.log(func(...args)); + }, + }), + ); + } + logValues(func = id) { + return this.log((_, hap) => func(hap.value)); + } } // TODO - adopt value.mjs fully..