Skip to content

Commit

Permalink
[update] add silentLoad on videoWrapper
Browse files Browse the repository at this point in the history
what:
why:
how:
  • Loading branch information
toxic-johann committed Jul 28, 2017
1 parent 505c644 commit bdcf00e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
21 changes: 9 additions & 12 deletions src/dispatcher/bus.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import {isEmpty, isArray, runRejectableQueue, runStoppableQueue, camelize, bind, isError, isVoid, isFunction, deepClone, Log} from 'chimee-helper';
import {videoEvents, kernelMethods, domEvents, domMethods, dispatcherMethods, noTriggerEvents} from 'helper/const';
import {videoEvents, kernelMethods, domEvents, domMethods, selfProcessorEvents} from 'helper/const';
const secondaryReg = /^(before|after|_)/;
/**
* <pre>
Expand Down Expand Up @@ -119,7 +119,10 @@ export default class Bus {
}
const beforeQueue = this._getEventQueue(event.before, this.__dispatcher.order);
return runRejectableQueue(beforeQueue, ...args)
.then(() => this._eventProcessor(key, {sync: false}, ...args))
.then(() => {
if(selfProcessorEvents.indexOf(key) > -1) return;
return this._eventProcessor(key, {sync: false}, ...args);
})
.catch(error => {
if(isError(error)) this.__dispatcher.throwError(error);
return Promise.reject(error);
Expand All @@ -142,7 +145,7 @@ export default class Bus {
return this._eventProcessor(key, {sync: true}, ...args);
}
const beforeQueue = this._getEventQueue(event.before, this.__dispatcher.order);
return runStoppableQueue(beforeQueue, ...args) && this._eventProcessor(key, {sync: true}, ...args);
return runStoppableQueue(beforeQueue, ...args) && selfProcessorEvents.indexOf(key) < 0 && this._eventProcessor(key, {sync: true}, ...args);
}
/**
* [Can only be called in dispatcher]trigger an event, which will run main -> after -> side effect period
Expand Down Expand Up @@ -324,16 +327,10 @@ export default class Bus {
_eventProcessor (key: string, {sync}: {sync: boolean}, ...args: any) {
const isKernelMethod: boolean = kernelMethods.indexOf(key) > -1;
const isDomMethod: boolean = domMethods.indexOf(key) > -1;
const isDispatcherMethod: boolean = dispatcherMethods.indexOf(key) > -1;
if(isKernelMethod || isDomMethod || isDispatcherMethod) {
if(isDispatcherMethod) {
this.__dispatcher[key](...args);
} else {
this.__dispatcher[isKernelMethod ? 'kernel' : 'dom'][key](...args);
}
if(isKernelMethod || isDomMethod) {
this.__dispatcher[isKernelMethod ? 'kernel' : 'dom'][key](...args);
if(videoEvents.indexOf(key) > -1 ||
domEvents.indexOf(key) > -1 ||
noTriggerEvents.indexOf(key) > -1) return true;
domEvents.indexOf(key) > -1) return true;
}
// $FlowFixMe: flow do not support computed sytax on classs, but it's ok here
return this[sync ? 'triggerSync' : 'trigger'](key, ...args);
Expand Down
1 change: 1 addition & 0 deletions src/dispatcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export default class Dispatcher {
const paused = this.dom.videoElement.paused;
this.switchKernel({video, kernel, config});
if(!paused) this.dom.videoElement.play();
return Promise.resolve();
});
}
switchKernel ({video, kernel, config}: {
Expand Down
9 changes: 7 additions & 2 deletions src/dispatcher/video-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,14 @@ export default @autobindClass() class VideoWrapper {
obj.__del(property);
}

@alias('silentLoad')
$silentLoad (...args: Array<*>) {

this.__dispatcher.silentLoad(...args);
return this.__dispatcher.bus.emit('silentLoad')
.then(() => {
return this.__dispatcher.silentLoad(...args);
}).then(result => {
this.__dispatcher.bus.trigger('silentLoad', result);
});
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/helper/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const domEvents = [
'msfullscreenchange',
'contextmenu'
];
export const noTriggerEvents = [
export const selfProcessorEvents = [
'silentLoad'
];
export const kernelMethods = [
Expand All @@ -79,9 +79,6 @@ export const kernelMethods = [
'load',
'seek'
];
export const dispatcherMethods = [
'silentLoad'
];
export const kernelEvents = [
'mediaInfo'
];
Expand Down

0 comments on commit bdcf00e

Please sign in to comment.