Skip to content

Commit

Permalink
Supports new fn/stream API without .broadcast()
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Oct 21, 2024
1 parent 41bd377 commit 32f742c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
26 changes: 14 additions & 12 deletions modules/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,19 @@ 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) => {
const children = state.elements.filter(isSlide);
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();

Expand All @@ -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] = {
Expand Down
21 changes: 10 additions & 11 deletions modules/scrollends.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

0 comments on commit 32f742c

Please sign in to comment.