Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "chimee", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "a video-player aims to bing wonderful experience on browser", | ||
@@ -57,2 +57,3 @@ "main": "lib/index.js", | ||
"babel-preset-stage-0": "^6.24.1", | ||
"chimee-helper": "^0.1.12", | ||
"eslint": "^4.2.0", | ||
@@ -59,0 +60,0 @@ "eslint-plugin-flowtype": "^2.35.0", |
@@ -362,2 +362,3 @@ // @flow | ||
isFunction(this.destroy) && this.destroy(); | ||
super.__destroy(); | ||
Object.keys(this.__events) | ||
@@ -364,0 +365,0 @@ .forEach(key => { |
@@ -43,3 +43,3 @@ // @flow | ||
if(!this.dispatcher.videoConfigReady) return value; | ||
value = isBoolean | ||
const val = isBoolean | ||
? value | ||
@@ -49,3 +49,3 @@ ? '' | ||
: value; | ||
this.dispatcher.dom.setAttr('video', set, value); | ||
this.dispatcher.dom.setAttr('video', set, val); | ||
return value; | ||
@@ -68,4 +68,6 @@ } | ||
if(!this.dispatcher.videoConfigReady) return value; | ||
if(isBoolean) value = value || undefined; | ||
this.dispatcher.dom.setAttr('video', attribute, value); | ||
const val = isBoolean | ||
? value || undefined | ||
: value; | ||
this.dispatcher.dom.setAttr('video', attribute, val); | ||
return value; | ||
@@ -153,6 +155,6 @@ } | ||
this.videoElement.playsInline = value; | ||
value = value ? '' : undefined; | ||
this.dispatcher.dom.setAttr('video', 'playsinline', value); | ||
this.dispatcher.dom.setAttr('video', 'webkit-playsinline', value); | ||
this.dispatcher.dom.setAttr('video', 'x5-video-player-type', value === '' ? 'h5' : undefined); | ||
const val = value ? '' : undefined; | ||
this.dispatcher.dom.setAttr('video', 'playsinline', val); | ||
this.dispatcher.dom.setAttr('video', 'webkit-playsinline', val); | ||
this.dispatcher.dom.setAttr('video', 'x5-video-player-type', value ? 'h5' : undefined); | ||
return value; | ||
@@ -261,2 +263,3 @@ } | ||
_realDomAttr = ['src', 'controls', 'width', 'height', 'crossOrigin', 'loop', 'muted', 'preload', 'poster', 'autoplay', 'playsInline', 'x5VideoPlayerFullScreen', 'x5VideoOrientation', 'xWebkitAirplay', 'playbackRate', 'defaultPlaybackRate', 'autoload', 'disableRemotePlayback', 'defaultMuted', 'volume']; | ||
lockKernelProperty () { | ||
@@ -263,0 +266,0 @@ applyDecorators(this, { |
// @flow | ||
import {bind} from 'chimee-helper'; | ||
import {bind, isString, getDeepProperty, isArray, isObject, isFunction, Log} from 'chimee-helper'; | ||
import {videoReadOnlyProperties, videoMethods, kernelMethods, domMethods} from 'helper/const'; | ||
import {accessor, nonenumerable, applyDecorators} from 'toxic-decorators'; | ||
import {accessor, nonenumerable, applyDecorators, watch} from 'toxic-decorators'; | ||
export default class VideoWrapper { | ||
__id: string; | ||
__dispatcher: Dispatcher; | ||
__unwatchHandlers: Array<Function>; | ||
__unwatchHandlers = []; | ||
__wrapAsVideo (videoConfig: VideoConfig) { | ||
@@ -81,2 +83,70 @@ // bind video read only properties on instance, so that you can get info like buffered | ||
} | ||
$watch (key: string | Array<string>, handler: Function, { | ||
deep, | ||
diff = true, | ||
other, | ||
proxy = false | ||
}: { | ||
deep?: boolean, | ||
diff?: boolean, | ||
other?: any, | ||
proxy?: boolean | ||
} = {}) { | ||
if(!isString(key) && !isArray(key)) throw new TypeError(`$watch only accept string and Array<string> as key to find the target to spy on, but not ${key}, whose type is ${typeof key}`); | ||
let watching = true; | ||
const watcher = function (...args) { | ||
if(watching) bind(handler, this)(...args); | ||
}; | ||
const unwatcher = () => { | ||
watching = false; | ||
const index = this.__unwatchHandlers.indexOf(unwatcher); | ||
if(index > -1) this.__unwatchHandlers.splice(index, 1); | ||
}; | ||
const keys = isString(key) | ||
? key.split('.') | ||
: key; | ||
const property = keys.pop(); | ||
const videoConfig = this.__dispatcher.videoConfig; | ||
const target = ( | ||
keys.length === 0 && | ||
!other && | ||
videoConfig._realDomAttr.indexOf(property) > -1 | ||
) | ||
? videoConfig | ||
: getDeepProperty(other || this, keys, {throwError: true}); | ||
applyDecorators(target, { | ||
[property]: watch(watcher, {deep, diff, proxy}) | ||
}, {self: true}); | ||
this.__unwatchHandlers.push(unwatcher); | ||
return unwatcher; | ||
} | ||
$set (obj: Object | Array<*>, property: string | number, value: any) { | ||
if(!isObject(obj) && !isArray(obj)) throw new TypeError(`$set only support Array or Object, but not ${obj}, whose type is ${typeof obj}`); | ||
// $FlowFixMe: we have custom this function | ||
if(!isFunction(obj.__set)) { | ||
Log.warn('chimee', `${JSON.stringify(obj)} has not been deep watch. There is no need to use $set.`); | ||
// $FlowFixMe: we support computed string on array here | ||
obj[property] = value; | ||
return; | ||
} | ||
obj.__set(property, value); | ||
} | ||
$del (obj: Object | Array<*>, property: string) { | ||
if(!isObject(obj) && !isArray(obj)) throw new TypeError(`$del only support Array or Object, but not ${obj}, whose type is ${typeof obj}`); | ||
// $FlowFixMe: we have custom this function | ||
if(!isFunction(obj.__del)) { | ||
Log.warn('chimee', `${JSON.stringify(obj)} has not been deep watch. There is no need to use $del.`); | ||
// $FlowFixMe: we support computed string on array here | ||
delete obj[property]; | ||
return; | ||
} | ||
obj.__del(property); | ||
} | ||
__destroy () { | ||
this.__unwatchHandlers.forEach(unwatcher => unwatcher()); | ||
} | ||
} |
@@ -65,2 +65,3 @@ // @flow | ||
destroy () { | ||
super.__destroy(); | ||
this.__dispatcher.destroy(); | ||
@@ -67,0 +68,0 @@ this.destroyed = true; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1824566
25
21
35905