Files
18500206848 91172a730c 11
2024-02-02 14:44:30 +08:00

60 lines
984 B
JavaScript

const defaultOptions = {
only: true
}
export default function markSlideListController(options = defaultOptions) {
const instances = {};
const opened = {};
const moving = {};
let index = 0;
const pipelines = {
moving: [],
opened: [],
closed: [],
};
init()
function init() {
if (options.only) {
pipelines.moving.push(only)
}
}
function pipelinesHandler(type, key) {
pipelines[type].forEach(item => {
item.call(this, key)
})
}
function only() {
for (let key in opened) {
const item = opened[key]
item.hide()
}
}
this.reg = ({
instance,
cb
}) => {
instances[index] = instance
cb(index++)
}
this.moving = (key) => {
moving[key] = instances[key]
delete opened[key]
pipelinesHandler('moving', key)
}
this.opened = (key) => {
opened[key] = instances[key]
delete moving[key]
pipelinesHandler('opened', key)
}
this.closed = (key) => {
delete opened[key]
delete moving[key]
pipelinesHandler('closed', key)
}
}