Open mojavelinux opened 9 years ago
wdyt @markdalgleish? Should we add this convenience or is this just something plugin authors need to live with? I don't want to add unnecessary bloat to bespoke.js core, so if you think we can live without this API, I'm willing to accept that.
I agree with you @mojavelinux, I think this could be helpful. This helper was present is DZslides :wink: I also think that it's not that we can live without it, the alternative is not that big/complex :stuck_out_tongue:
:warning: If we add this to core, we should not bind a fixed length. Authoring tools could inject slides and change the slide deck length at runtime.
I'm pretty sure I got the idea from DZSlides (or, perhaps I should say, DZSlides had spoiled me).
One of the key arguments for this change is that it really starts to add up across a collection of plugins. The property "length" doesn't get minimized, and it takes two steps to get to it. And many plugins have this somewhere in the code. (That may even be a strong case for "first" and "last" methods, though those are harder to work with in dynamic code).
We would need something like this then :
deck = {
on: on,
off: off,
fire: fire,
slide: slide,
next: step.bind(null, 1),
prev: step.bind(null, -1),
// new helpers here :
first: slide.bind(null, 0),
last: function () {
deck.slide(deck.slides.length - 1);
},
// new helpers !
slides: slides
};
I think that this way, it would be truly dynamic.
Or as you proposed, we do not add new helpers and we just use 0 and -1. This would require to update activate
like this :
We would need something like this then :
activate = function(index, customData) {
if (index === -1) {
index = deck.slides.length - 1;
}
else if (!slides[index]) {
return;
}
fire('deactivate', createEventData(activeSlide, customData));
activeSlide = slides[index];
fire('activate', createEventData(activeSlide, customData));
},
To make life for plugin authors simpler, it would be nice if
deck.slide(-1)
went to the last slide to avoid having to constantly type:If this isn't acceptable, a reasonable compromise might be to add a
deck.end()
method to advance to the last slide.