From 41bd377422fc6bc30c754602ff1d5b78a89267f0 Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 15 Oct 2024 14:37:06 +0200 Subject: [PATCH 1/2] Signalification --- module.js | 2 +- modules/lifecycle.js | 4 ++-- modules/properties.js | 4 ++-- modules/scrollends.js | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/module.js b/module.js index bad2ad9..8bb0198 100644 --- a/module.js +++ b/module.js @@ -46,7 +46,7 @@ A `` is not just for images. Content may be any HTML. Here's a // https://caniuse.com/?search=scrollto //import 'dom/polyfills/element.scrollto.js'; -import element from 'dom/element.js'; +import element from 'dom/element-1.js'; import lifecycle from './modules/lifecycle.js'; import properties from './modules/properties.js'; diff --git a/modules/lifecycle.js b/modules/lifecycle.js index cd3de3e..9b82a54 100644 --- a/modules/lifecycle.js +++ b/modules/lifecycle.js @@ -71,8 +71,8 @@ export default { shadow.append(slides, controls); // Stream to push load to - const connects = Stream.broadcast(); - const load = Stream.broadcast(); + const connects = Stream.of(); + const load = Stream.of(); // In Chrome and FF initial `slotchange` event is always sent before // load, but not so in Safari where either order may happen (at a guess diff --git a/modules/properties.js b/modules/properties.js index 51b0914..35d9968 100644 --- a/modules/properties.js +++ b/modules/properties.js @@ -1,6 +1,6 @@ -import createBoolean from 'dom/element/create-boolean.js'; -import createTokenList from 'dom/element/create-token-list.js'; +import createBoolean from 'dom/element-1/create-boolean.js'; +import createTokenList from 'dom/element-1/create-token-list.js'; import { $data } from './consts.js'; import * as autoplay from './autoplay.js'; diff --git a/modules/scrollends.js b/modules/scrollends.js index dc31964..ee43f49 100644 --- a/modules/scrollends.js +++ b/modules/scrollends.js @@ -2,7 +2,7 @@ // Much of this code has been purloined from targetable.js – do we need the // hashchange tracking here? I have commented it -import Stream, { stop } from 'fn/stream/stream.js'; +import Stream from 'fn/stream/stream.js'; import { getScrollInterval, updateScrollInterval } from './consts.js'; const assign = Object.assign; @@ -47,7 +47,7 @@ assign(ScrollendsProducer.prototype, { stop: function() { this.element.removeEventListener('scroll', this); - stop(this.stream); + Stream.stop(this.stream); } }); From 32f742cdbec23b403e7430a6993e7ddd49ba5620 Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 21 Oct 2024 19:15:25 +0200 Subject: [PATCH 2/2] 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); }