@smartface/contx
Advanced tools
Comparing version 1.0.0-rc.5 to 1.0.0-rc.6
@@ -138,4 +138,4 @@ (function (global, factory) { | ||
} catch (e) { | ||
e.message = "An Error is occurred When action [" + action.name + "] run on target [" + target + "]. " + e.message; | ||
throw e; | ||
e.message = "An Error is occurred When action [" + action.type + "] run on target [" + target + "]. " + e.message; | ||
throw new Error(e); | ||
} | ||
@@ -142,0 +142,0 @@ }; |
@@ -85,2 +85,22 @@ (function (global, factory) { | ||
function createOriginals(component) { | ||
!component.__original_addChild && Object.defineProperty(component, "__original_addChild", { | ||
value: component.addChild, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
!component.__original_removeChild && Object.defineProperty(component, "__original_removeChild", { | ||
value: component.removeChild, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
!component.__original_removeAll && Object.defineProperty(component, "__original_removeAll", { | ||
value: component.removeAll, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
} | ||
/** | ||
@@ -111,30 +131,53 @@ * Extract components tree from a SF Component | ||
if (component.layout && typeof component.layout.addChild === 'function') { | ||
Object.defineProperty(component.layout, "addChild", { | ||
value: addChild.bind(component, component.layout.addChild.bind(component.layout)) | ||
}); | ||
try { | ||
if (component.layout && typeof component.layout.addChild === 'function') { | ||
createOriginals(component.layout); | ||
Object.defineProperty(component.layout, "addChild", { | ||
value: addChild.bind(component, component.layout.__original_addChild.bind(component.layout)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
component.layout.removeChild && Object.defineProperty(component.layout, "removeChild", { | ||
value: removeChild.bind(component, component.layout.removeChild.bind(component.layout)) | ||
}); | ||
component.layout.removeChild && Object.defineProperty(component.layout, "removeChild", { | ||
value: removeChild.bind(component, component.layout.__original_removeChild.bind(component.layout)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
component.layout.removeAll && Object.defineProperty(component.layout, "removeAll", { | ||
value: removeChildren.bind(component, component.layout.removeAll.bind(component.layout)) | ||
}); | ||
} else if (typeof component.addChild === 'function') { | ||
Object.defineProperty(component, "addChild", { | ||
value: addChild.bind(component, component.addChild.bind(component)) | ||
}); | ||
component.layout.removeAll && Object.defineProperty(component.layout, "removeAll", { | ||
value: removeChildren.bind(component, component.layout.__original_removeAll.bind(component.layout)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} else if (typeof component.addChild === 'function') { | ||
createOriginals(component); | ||
component.removeChild && Object.defineProperty(component, "removeChild", { | ||
value: removeChild.bind(component, component.removeChild.bind(component)) | ||
}); | ||
Object.defineProperty(component, "addChild", { | ||
value: addChild.bind(component, component.__original_addChild.bind(component)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
component.removeAll && Object.defineProperty(component, "removeAll", { | ||
value: removeChildren.bind(component, component.removeAll.bind(component)) | ||
}); | ||
} else { | ||
component.removeChild && Object.defineProperty(component, "removeChild", { | ||
value: removeChild.bind(component) | ||
}); | ||
component.removeChild && Object.defineProperty(component, "removeChild", { | ||
value: removeChild.bind(component, component.__original_removeChild.bind(component)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
component.removeAll && Object.defineProperty(component, "removeAll", { | ||
value: removeChildren.bind(component, component.__original_removeAll.bind(component)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} else { | ||
!component.removeChild && Object.defineProperty(component, "removeChild", { | ||
value: removeChild.bind(component), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} | ||
} catch (e) { | ||
e.message = 'An Error is occurred when component [' + name + '] is patched in the [' + rootName + ']. ' + e.message; | ||
(0, _raiseErrorMaybe2.default)(new Error(e), component.onError); | ||
} | ||
@@ -141,0 +184,0 @@ |
@@ -91,3 +91,3 @@ (function (global, factory) { | ||
type: _isTablet2.default ? "tablet" : "phone", | ||
orientation: _screen2.default.width > _screen2.default.height ? "portrait" : "landscape", | ||
orientation: _screen2.default.width > _screen2.default.height ? "landscape" : "portrait", | ||
language: _system2.default.language | ||
@@ -147,8 +147,7 @@ }; | ||
return function diffStylingReducer(acc, key) { | ||
//align is readolnly issue | ||
// if (key === 'align') { | ||
// delete acc[key]; | ||
// return acc; | ||
// } else | ||
if (key == "flexProps") { | ||
// align is readolnly issue on Android | ||
if (key === 'align') { | ||
delete acc[key]; | ||
return acc; | ||
} else if (key == "flexProps") { | ||
Object.keys(newStyles[key]).forEach(function (name) { | ||
@@ -155,0 +154,0 @@ if (oldStyles[key] === undefined || newStyles[key][name] !== oldStyles[key][name]) { |
@@ -61,13 +61,2 @@ (function (global, factory) { | ||
// {"backgroundColor":{"nativeObject":{}},"paddingLeft":10,"paddingRight":10,"paddingTop":null,"paddingBottom":10,"flexDirection":0,"alignItems":2,"direction":0,"flexWrap":0,"justifyContent":4} | ||
// function addChild(componentAddChild, child, actor) { | ||
// componentAddChild(child); | ||
// actor.dispatch({ type: "invalidateContext" }); | ||
// } | ||
// function addChild(componentAddChild, child, actor) { | ||
// componentAddChild(child); | ||
// } | ||
// TODO create new jsdoc type for the parameter | ||
@@ -111,3 +100,2 @@ /** | ||
_this.setStyles = function (style) { | ||
var reduceDiffStyleHook = _this.hook("reduceDiffStyleHook"); | ||
@@ -166,92 +154,82 @@ | ||
// this.name = name; | ||
_this.classNames = [].concat(initialClassNames); | ||
// componentVars.classNames && | ||
// (this.classNames = this.classNames.concat(componentVars.classNames.split(" "))); | ||
// className && this.classNames.push(className); | ||
// initialClassNames = [...this.classNames]; | ||
_this.styles = initialProps; | ||
_this.isDirty = true; | ||
_this.getStyles = function () { | ||
return _this.styles ? Object.assign({}, _this.styles) : {}; | ||
}; | ||
// if (typeof component.addChild === "function") | ||
// component.addContextChild = addChild.bind(component, this); | ||
// else if(name.indexOf("statusBar") == -1 && typeof component.layout.addChild === "function") | ||
// component.layout.addContextChild = addChild.bind(component, component.layout.addChild.bind(component.layout), this); | ||
return _this; | ||
} | ||
_this.getClassName = function () { | ||
return _this.classNames.join(" "); | ||
}; | ||
/** | ||
* Sets styles | ||
* | ||
* @param {object} styles - a style object | ||
*/ | ||
_this.classNamesCount = function () { | ||
return _this.classNames.length; | ||
}; | ||
_this.removeClassName = function (className) { | ||
if (_this.hasClassName(className)) { | ||
_this.isDirty = true; | ||
_this.classNames = _this.classNames.filter(function (cname) { | ||
return cname !== className; | ||
}); | ||
} | ||
Stylable.prototype.getStyles = function getStyles() { | ||
return this.styles ? Object.assign({}, this.styles) : {}; | ||
}; | ||
return _this.getClassName(); | ||
}; | ||
Stylable.prototype.getInitialClassName = function getInitialClassName() { | ||
return initialClassNames; | ||
}; | ||
_this.resetClassNames = function () { | ||
var classNames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
Stylable.prototype.getClassName = function getClassName() { | ||
return this.classNames.join(" "); | ||
}; | ||
_this.classNames = [].concat(initialClassNames, classNames); | ||
_this.isDirty = true; | ||
}; | ||
Stylable.prototype.classNamesCount = function classNamesCount() { | ||
return this.classNames.length; | ||
}; | ||
Stylable.prototype.removeClassName = function removeClassName(className) { | ||
if (this.hasClassName(className)) { | ||
this.isDirty = true; | ||
this.classNames = this.classNames.filter(function (cname) { | ||
return cname !== className; | ||
_this.hasClassName = function (className) { | ||
return _this.classNames.some(function (cname) { | ||
return cname === className; | ||
}); | ||
} | ||
}; | ||
return this.getClassName(); | ||
}; | ||
_this.pushClassNames = function (classNames) { | ||
if (!_this.hasClassName(classNames)) { | ||
Array.isArray(classNames) ? _this.classNames = [].concat(_this.classNames, classNames) : _this.classNames.push(classNames); | ||
Stylable.prototype.resetClassNames = function resetClassNames() { | ||
var classNames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
_this.isDirty = true; | ||
} | ||
this.classNames = [].concat(initialClassNames, classNames); | ||
this.isDirty = true; | ||
}; | ||
return _this.getClassName(); | ||
}; | ||
Stylable.prototype.hasClassName = function hasClassName(className) { | ||
return this.classNames.some(function (cname) { | ||
return cname === className; | ||
}); | ||
}; | ||
_this.addClassName = function (className, index) { | ||
if (!_this.hasClassName(className)) { | ||
_this.classNames.splice(index, 1, className); | ||
_this.isDirty = true; | ||
} | ||
Stylable.prototype.pushClassNames = function pushClassNames(classNames) { | ||
if (!this.hasClassName(classNames)) { | ||
Array.isArray(classNames) ? this.classNames = [].concat(this.classNames, classNames) : this.classNames.push(classNames); | ||
return _this.getClassName(); | ||
}; | ||
this.isDirty = true; | ||
} | ||
_this.dispose = function () { | ||
component.setContextDispatcher && component.setContextDispatcher(null); | ||
_this._actorInternal_.component = null; | ||
_this._actorInternal_ = null; | ||
_this.context = null; | ||
_this.styles = null; | ||
component.onDispose && component.onDispose(); | ||
component = null; | ||
}; | ||
return this.getClassName(); | ||
}; | ||
_this.classNames = [].concat(initialClassNames); | ||
_this.styles = initialProps; | ||
_this.isDirty = true; | ||
return _this; | ||
} | ||
Stylable.prototype.addClassName = function addClassName(className, index) { | ||
if (!this.hasClassName(className)) { | ||
this.classNames.splice(index, 1, className); | ||
this.isDirty = true; | ||
} | ||
/** | ||
* Sets styles | ||
* | ||
* @param {object} styles - a style object | ||
*/ | ||
return this.getClassName(); | ||
}; | ||
Stylable.prototype.dispose = function dispose() { | ||
component.setContextDispatcher && component.setContextDispatcher(null); | ||
this._actorInternal_.component = null; | ||
this._actorInternal_ = null; | ||
this.context = null; | ||
this.styles = null; | ||
component.onDispose && component.onDispose(); | ||
component = null; | ||
Stylable.prototype.getInitialClassName = function getInitialClassName() { | ||
return initialClassNames; | ||
}; | ||
@@ -258,0 +236,0 @@ |
{ | ||
"name": "@smartface/contx", | ||
"version": "1.0.0-rc.5", | ||
"version": "1.0.0-rc.6", | ||
"description": "Context Manager", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -109,4 +109,4 @@ import {INIT_CONTEXT_ACTION_TYPE} from "./constants"; | ||
} catch (e) { | ||
e.message = `An Error is occurred When action [${action.name}] run on target [${target}]. ${e.message}`; | ||
throw e; | ||
e.message = `An Error is occurred When action [${action.type}] run on target [${target}]. ${e.message}`; | ||
throw new Error(e); | ||
} | ||
@@ -113,0 +113,0 @@ } |
@@ -30,2 +30,22 @@ import hooks from '../core/hooks'; | ||
function createOriginals(component){ | ||
!component.__original_addChild && Object.defineProperty(component, "__original_addChild", { | ||
value: component.addChild, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
!component.__original_removeChild && Object.defineProperty(component, "__original_removeChild", { | ||
value: component.removeChild, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
!component.__original_removeAll && Object.defineProperty(component, "__original_removeAll", { | ||
value: component.removeAll, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
} | ||
/** | ||
@@ -54,30 +74,53 @@ * Extract components tree from a SF Component | ||
if(component.layout && typeof component.layout.addChild === 'function'){ | ||
Object.defineProperty(component.layout, "addChild", { | ||
value: addChild.bind(component, component.layout.addChild.bind(component.layout)) | ||
}); | ||
try { | ||
if(component.layout && typeof component.layout.addChild === 'function'){ | ||
createOriginals(component.layout); | ||
Object.defineProperty(component.layout, "addChild", { | ||
value: addChild.bind(component, component.layout.__original_addChild.bind(component.layout)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
component.layout.removeChild && Object.defineProperty(component.layout, "removeChild", { | ||
value: removeChild.bind(component, component.layout.__original_removeChild.bind(component.layout)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
component.layout.removeAll && Object.defineProperty(component.layout, "removeAll", { | ||
value: removeChildren.bind(component, component.layout.__original_removeAll.bind(component.layout)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} else if(typeof component.addChild === 'function'){ | ||
createOriginals(component); | ||
Object.defineProperty(component, "addChild", { | ||
value: addChild.bind(component, component.__original_addChild.bind(component)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
component.removeChild && Object.defineProperty(component, "removeChild", { | ||
value: removeChild.bind(component, component.__original_removeChild.bind(component)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
component.removeAll && Object.defineProperty(component, "removeAll", { | ||
value: removeChildren.bind(component, component.__original_removeAll.bind(component)), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} else { | ||
!component.removeChild && Object.defineProperty(component, "removeChild", { | ||
value: removeChild.bind(component), | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} | ||
} catch (e) { | ||
e.message = `An Error is occurred when component [${name}] is patched in the [${rootName}]. ${e.message}`; | ||
component.layout.removeChild && Object.defineProperty(component.layout, "removeChild", { | ||
value: removeChild.bind(component, component.layout.removeChild.bind(component.layout)) | ||
}); | ||
component.layout.removeAll && Object.defineProperty(component.layout, "removeAll", { | ||
value: removeChildren.bind(component, component.layout.removeAll.bind(component.layout)) | ||
}); | ||
} else if(typeof component.addChild === 'function'){ | ||
Object.defineProperty(component, "addChild", { | ||
value: addChild.bind(component, component.addChild.bind(component)) | ||
}); | ||
component.removeChild && Object.defineProperty(component, "removeChild", { | ||
value: removeChild.bind(component, component.removeChild.bind(component)) | ||
}); | ||
component.removeAll && Object.defineProperty(component, "removeAll", { | ||
value: removeChildren.bind(component, component.removeAll.bind(component)) | ||
}); | ||
} else { | ||
component.removeChild && Object.defineProperty(component, "removeChild", { | ||
value: removeChild.bind(component) | ||
}); | ||
raiseErrorMaybe(new Error(e), component.onError); | ||
} | ||
@@ -84,0 +127,0 @@ |
@@ -30,3 +30,3 @@ import * as StyleContext from "../styling/StyleContext"; | ||
type: isTablet ? "tablet" : "phone", | ||
orientation: Screen.width > Screen.height ? "portrait" : "landscape", | ||
orientation: Screen.width > Screen.height ? "landscape" : "portrait", | ||
language: System.language | ||
@@ -85,8 +85,7 @@ }; | ||
return function diffStylingReducer(acc, key) { | ||
//align is readolnly issue | ||
// if (key === 'align') { | ||
// delete acc[key]; | ||
// return acc; | ||
// } else | ||
if (key == "flexProps") { | ||
// align is readolnly issue on Android | ||
if (key === 'align') { | ||
delete acc[key]; | ||
return acc; | ||
} else if (key == "flexProps") { | ||
Object.keys(newStyles[key]) | ||
@@ -93,0 +92,0 @@ .forEach(function(name) { |
import Actor from "../core/Actor"; | ||
import merge from "@smartface/styler/lib/utils/merge"; | ||
// {"backgroundColor":{"nativeObject":{}},"paddingLeft":10,"paddingRight":10,"paddingTop":null,"paddingBottom":10,"flexDirection":0,"alignItems":2,"direction":0,"flexWrap":0,"justifyContent":4} | ||
// function addChild(componentAddChild, child, actor) { | ||
// componentAddChild(child); | ||
// actor.dispatch({ type: "invalidateContext" }); | ||
// } | ||
// function addChild(componentAddChild, child, actor) { | ||
// componentAddChild(child); | ||
// } | ||
// TODO create new jsdoc type for the parameter | ||
@@ -37,15 +26,5 @@ /** | ||
// this.name = name; | ||
this.classNames = [...initialClassNames]; | ||
// componentVars.classNames && | ||
// (this.classNames = this.classNames.concat(componentVars.classNames.split(" "))); | ||
// className && this.classNames.push(className); | ||
// initialClassNames = [...this.classNames]; | ||
this.styles = initialProps; | ||
this.isDirty = true; | ||
// if (typeof component.addChild === "function") | ||
// component.addContextChild = addChild.bind(component, this); | ||
// else if(name.indexOf("statusBar") == -1 && typeof component.layout.addChild === "function") | ||
// component.layout.addContextChild = addChild.bind(component, component.layout.addChild.bind(component.layout), this); | ||
} | ||
@@ -63,7 +42,6 @@ | ||
setStyles = (style) => { | ||
const reduceDiffStyleHook = this.hook("reduceDiffStyleHook"); | ||
let diffReducer = reduceDiffStyleHook | ||
? reduceDiffStyleHook(this.styles || {}, style) | ||
let diffReducer = reduceDiffStyleHook | ||
? reduceDiffStyleHook(this.styles || {}, style) | ||
: (acc, key) => { | ||
@@ -122,3 +100,3 @@ if (this.styles[key] !== undefined) { | ||
getStyles() { | ||
getStyles = () => { | ||
return this.styles ? Object.assign({}, this.styles) : {}; | ||
@@ -131,24 +109,11 @@ } | ||
getClassName() { | ||
getClassName = () => { | ||
return this.classNames.join(" "); | ||
} | ||
/* addChild = (child) => { | ||
this.component.layout | ||
? this.component.layout.addChild(child) | ||
: this.component.addChild(child); | ||
} | ||
removeChild = (child) => { | ||
this.component.layout | ||
? this.component.layout.removeChild(child) | ||
: this.component.removeChild(child); | ||
} | ||
*/ | ||
classNamesCount() { | ||
classNamesCount = () => { | ||
return this.classNames.length; | ||
} | ||
removeClassName(className) { | ||
removeClassName = (className) => { | ||
if (this.hasClassName(className)) { | ||
@@ -164,3 +129,3 @@ this.isDirty = true; | ||
resetClassNames(classNames = []) { | ||
resetClassNames = (classNames = []) => { | ||
this.classNames = [...initialClassNames, ...classNames]; | ||
@@ -170,3 +135,3 @@ this.isDirty = true; | ||
hasClassName(className) { | ||
hasClassName = (className) => { | ||
return this.classNames.some((cname) => { | ||
@@ -177,3 +142,3 @@ return cname === className; | ||
pushClassNames(classNames) { | ||
pushClassNames = (classNames) => { | ||
if (!this.hasClassName(classNames)) { | ||
@@ -190,3 +155,3 @@ Array.isArray(classNames) | ||
addClassName(className, index) { | ||
addClassName = (className, index) => { | ||
if (!this.hasClassName(className)) { | ||
@@ -200,3 +165,3 @@ this.classNames.splice(index, 1, className); | ||
dispose() { | ||
dispose = () => { | ||
component.setContextDispatcher && | ||
@@ -203,0 +168,0 @@ component.setContextDispatcher(null); |
105470
2873