project init
This commit is contained in:
59
components/mark-slide-list/controller.js
Normal file
59
components/mark-slide-list/controller.js
Normal file
@@ -0,0 +1,59 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user