Skip to content

Commit

Permalink
Merge branch 'main' of github.com:stephband/slide-show
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Oct 21, 2024
2 parents 4999318 + 32f742c commit f221a49
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion module.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ A `<slide-show>` 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';

Expand Down
30 changes: 16 additions & 14 deletions modules/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions modules/properties.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
23 changes: 11 additions & 12 deletions modules/scrollends.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
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 f221a49

Please sign in to comment.