From 32f742cdbec23b403e7430a6993e7ddd49ba5620 Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 21 Oct 2024 19:15:25 +0200 Subject: [PATCH] Supports new fn/stream API without .broadcast() --- modules/lifecycle.js | 26 ++++++++++++++------------ modules/scrollends.js | 21 ++++++++++----------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/modules/lifecycle.js b/modules/lifecycle.js index 9b82a54..4b5e584 100644 --- a/modules/lifecycle.js +++ b/modules/lifecycle.js @@ -83,8 +83,8 @@ export default { host: load, elements: events('slotchange', slot) .map((e) => data.elements = slot.assignedElements()), - }) - .broadcast({ memory: true }); + }); + //.broadcast({ memory: true }); const mutations = slotchanges .map((state) => { @@ -92,9 +92,10 @@ export default { return equals(data.children, children) ? undefined : (data.children = children) ; - }) - .broadcast({ memory: true, hot: true }); - + }); + //.broadcast({ memory: true, hot: true }); +// Keep it hot +mutations.pipe({ push: noop }); // Buffer stream for pushing children to scroll into view then activate const views = Stream.of(); @@ -108,18 +109,19 @@ export default { child )) .filter((child) => (data.active !== child && trigger('slide-active', child))) - .map((child) => data.active = child) - .broadcast({ memory: true, hot: true }); - + .map((child) => data.active = child); + //.broadcast({ memory: true, hot: true }); +// Keep it hot +actives.pipe({ push: noop }); const clicks = events('click', shadow) - .filter(isPrimaryButton) - .broadcast(); + .filter(isPrimaryButton); + //.broadcast(); // Track when scroll comes to rest... const scrolls = scrollends(slides) // ...but not after disconnect or mid finger gesture... - .filter((e) => (data.connected && !data.gesturing)) - .broadcast(); + .filter((e) => (data.connected && !data.gesturing)); + //.broadcast(); // Private data const data = this[$data] = { diff --git a/modules/scrollends.js b/modules/scrollends.js index ee43f49..3f8dd3d 100644 --- a/modules/scrollends.js +++ b/modules/scrollends.js @@ -14,24 +14,23 @@ const captureOptions = { passive: true }; -function fire(producer, e) { - producer.timer = undefined; - producer.stream.push(e); - - const times = producer.times; +function fire(stream, e) { + stream.timer = undefined; + Stream.push(stream, e); + const times = stream.times; if (times.length > 1) { updateScrollInterval(times); } times.length = 0; } -function ScrollendsProducer(element) { +function Scrollends(element) { this.element = element; this.times = []; } -assign(ScrollendsProducer.prototype, { - pipe: function(stream) { - this.stream = stream; +assign(Scrollends.prototype, Stream.prototype, { + start: function(stream) { this.element.addEventListener('scroll', this, captureOptions); + return this; }, handleEvent: function(e) { @@ -47,10 +46,10 @@ assign(ScrollendsProducer.prototype, { stop: function() { this.element.removeEventListener('scroll', this); - Stream.stop(this.stream); + return Stream.stop(this); } }); export default function scrollends(element) { - return new Stream(new ScrollendsProducer(element)); + return new Scrollends(element); }