feat:Add InconsistProperty decorator because sometimes the property in js side cannot be consist with natiive side
This commit is contained in:
parent
d13948223e
commit
28519d20c7
@ -185,6 +185,18 @@ function Property(target, propKey) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function InconsistProperty(target, propKey) {
|
||||||
|
Object.defineProperty(target, propKey, {
|
||||||
|
get: function () {
|
||||||
|
return Reflect.get(this, "__prop__" + propKey, this);
|
||||||
|
},
|
||||||
|
set: function (v) {
|
||||||
|
var oldV = Reflect.get(this, "__prop__" + propKey, this);
|
||||||
|
Reflect.set(this, "__prop__" + propKey, v, this);
|
||||||
|
Reflect.apply(this.onPropertyChanged, this, [propKey, oldV, v]);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
var View = /** @class */ (function () {
|
var View = /** @class */ (function () {
|
||||||
function View() {
|
function View() {
|
||||||
this.width = 0;
|
this.width = 0;
|
||||||
@ -3546,6 +3558,7 @@ exports.Gravity = Gravity;
|
|||||||
exports.Group = Group;
|
exports.Group = Group;
|
||||||
exports.HLayout = HLayout;
|
exports.HLayout = HLayout;
|
||||||
exports.Image = Image;
|
exports.Image = Image;
|
||||||
|
exports.InconsistProperty = InconsistProperty;
|
||||||
exports.Input = Input;
|
exports.Input = Input;
|
||||||
exports.LEFT = LEFT;
|
exports.LEFT = LEFT;
|
||||||
exports.LayoutConfigImpl = LayoutConfigImpl;
|
exports.LayoutConfigImpl = LayoutConfigImpl;
|
||||||
|
@ -125,8 +125,13 @@ var __decorate$d = (undefined && undefined.__decorate) || function (decorators,
|
|||||||
var __metadata$d = (undefined && undefined.__metadata) || function (k, v) {
|
var __metadata$d = (undefined && undefined.__metadata) || function (k, v) {
|
||||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||||
};
|
};
|
||||||
|
const PROP_CONSIST = 1;
|
||||||
|
const PROP_INCONSIST = 2;
|
||||||
function Property(target, propKey) {
|
function Property(target, propKey) {
|
||||||
Reflect.defineMetadata(propKey, true, target);
|
Reflect.defineMetadata(propKey, PROP_CONSIST, target);
|
||||||
|
}
|
||||||
|
function InconsistProperty(target, propKey) {
|
||||||
|
Reflect.defineMetadata(propKey, PROP_INCONSIST, target);
|
||||||
}
|
}
|
||||||
class View {
|
class View {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -150,7 +155,10 @@ class View {
|
|||||||
set: (target, p, v, receiver) => {
|
set: (target, p, v, receiver) => {
|
||||||
const oldV = Reflect.get(target, p, receiver);
|
const oldV = Reflect.get(target, p, receiver);
|
||||||
const ret = Reflect.set(target, p, v, receiver);
|
const ret = Reflect.set(target, p, v, receiver);
|
||||||
if (Reflect.getMetadata(p, target) && oldV !== v) {
|
if (Reflect.getMetadata(p, target) === PROP_CONSIST && oldV !== v) {
|
||||||
|
receiver.onPropertyChanged(p.toString(), oldV, v);
|
||||||
|
}
|
||||||
|
else if (Reflect.getMetadata(p, target) === PROP_INCONSIST) {
|
||||||
receiver.onPropertyChanged(p.toString(), oldV, v);
|
receiver.onPropertyChanged(p.toString(), oldV, v);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -2736,6 +2744,7 @@ exports.Gravity = Gravity;
|
|||||||
exports.Group = Group;
|
exports.Group = Group;
|
||||||
exports.HLayout = HLayout;
|
exports.HLayout = HLayout;
|
||||||
exports.Image = Image;
|
exports.Image = Image;
|
||||||
|
exports.InconsistProperty = InconsistProperty;
|
||||||
exports.Input = Input;
|
exports.Input = Input;
|
||||||
exports.LEFT = LEFT;
|
exports.LEFT = LEFT;
|
||||||
exports.LayoutConfigImpl = LayoutConfigImpl;
|
exports.LayoutConfigImpl = LayoutConfigImpl;
|
||||||
|
@ -1620,8 +1620,13 @@ var __decorate$d = (undefined && undefined.__decorate) || function (decorators,
|
|||||||
var __metadata$d = (undefined && undefined.__metadata) || function (k, v) {
|
var __metadata$d = (undefined && undefined.__metadata) || function (k, v) {
|
||||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||||
};
|
};
|
||||||
|
const PROP_CONSIST = 1;
|
||||||
|
const PROP_INCONSIST = 2;
|
||||||
function Property(target, propKey) {
|
function Property(target, propKey) {
|
||||||
Reflect.defineMetadata(propKey, true, target);
|
Reflect.defineMetadata(propKey, PROP_CONSIST, target);
|
||||||
|
}
|
||||||
|
function InconsistProperty(target, propKey) {
|
||||||
|
Reflect.defineMetadata(propKey, PROP_INCONSIST, target);
|
||||||
}
|
}
|
||||||
class View {
|
class View {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -1645,7 +1650,10 @@ class View {
|
|||||||
set: (target, p, v, receiver) => {
|
set: (target, p, v, receiver) => {
|
||||||
const oldV = Reflect.get(target, p, receiver);
|
const oldV = Reflect.get(target, p, receiver);
|
||||||
const ret = Reflect.set(target, p, v, receiver);
|
const ret = Reflect.set(target, p, v, receiver);
|
||||||
if (Reflect.getMetadata(p, target) && oldV !== v) {
|
if (Reflect.getMetadata(p, target) === PROP_CONSIST && oldV !== v) {
|
||||||
|
receiver.onPropertyChanged(p.toString(), oldV, v);
|
||||||
|
}
|
||||||
|
else if (Reflect.getMetadata(p, target) === PROP_INCONSIST) {
|
||||||
receiver.onPropertyChanged(p.toString(), oldV, v);
|
receiver.onPropertyChanged(p.toString(), oldV, v);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -4403,9 +4411,11 @@ global$1.nativeLog = (type, msg) => {
|
|||||||
};
|
};
|
||||||
global$1.nativeRequire = () => {
|
global$1.nativeRequire = () => {
|
||||||
console.error("Do not call nativeRequire here");
|
console.error("Do not call nativeRequire here");
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
global$1.nativeBridge = () => {
|
global$1.nativeBridge = () => {
|
||||||
console.error("Do not call nativeBridge here");
|
console.error("Do not call nativeBridge here");
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.AnimationSet = AnimationSet;
|
exports.AnimationSet = AnimationSet;
|
||||||
@ -4423,6 +4433,7 @@ exports.Gravity = Gravity;
|
|||||||
exports.Group = Group;
|
exports.Group = Group;
|
||||||
exports.HLayout = HLayout;
|
exports.HLayout = HLayout;
|
||||||
exports.Image = Image;
|
exports.Image = Image;
|
||||||
|
exports.InconsistProperty = InconsistProperty;
|
||||||
exports.Input = Input;
|
exports.Input = Input;
|
||||||
exports.LEFT = LEFT;
|
exports.LEFT = LEFT;
|
||||||
exports.LayoutConfigImpl = LayoutConfigImpl;
|
exports.LayoutConfigImpl = LayoutConfigImpl;
|
||||||
|
1
doric-js/index.d.ts
vendored
1
doric-js/index.d.ts
vendored
@ -177,6 +177,7 @@ declare module 'doric/lib/src/ui/view' {
|
|||||||
import { IAnimation } from "doric/lib/src/ui/animation";
|
import { IAnimation } from "doric/lib/src/ui/animation";
|
||||||
import { FlexConfig } from "doric/lib/src/util/flexbox";
|
import { FlexConfig } from "doric/lib/src/util/flexbox";
|
||||||
export function Property(target: Object, propKey: string): void;
|
export function Property(target: Object, propKey: string): void;
|
||||||
|
export function InconsistProperty(target: Object, propKey: string): void;
|
||||||
export type NativeViewModel = {
|
export type NativeViewModel = {
|
||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
|
@ -203,8 +203,10 @@ global.nativeLog = (type, msg) => {
|
|||||||
};
|
};
|
||||||
global.nativeRequire = () => {
|
global.nativeRequire = () => {
|
||||||
console.error("Do not call nativeRequire here");
|
console.error("Do not call nativeRequire here");
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
global.nativeBridge = () => {
|
global.nativeBridge = () => {
|
||||||
console.error("Do not call nativeBridge here");
|
console.error("Do not call nativeBridge here");
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
export * from './index';
|
export * from './index';
|
||||||
|
1
doric-js/lib/src/ui/view.d.ts
vendored
1
doric-js/lib/src/ui/view.d.ts
vendored
@ -5,6 +5,7 @@ import { LayoutConfig } from '../util/layoutconfig';
|
|||||||
import { IAnimation } from "./animation";
|
import { IAnimation } from "./animation";
|
||||||
import { FlexConfig } from "../util/flexbox";
|
import { FlexConfig } from "../util/flexbox";
|
||||||
export declare function Property(target: Object, propKey: string): void;
|
export declare function Property(target: Object, propKey: string): void;
|
||||||
|
export declare function InconsistProperty(target: Object, propKey: string): void;
|
||||||
export declare type NativeViewModel = {
|
export declare type NativeViewModel = {
|
||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
|
@ -10,8 +10,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|||||||
import { obj2Model } from "../util/types";
|
import { obj2Model } from "../util/types";
|
||||||
import { uniqueId } from "../util/uniqueId";
|
import { uniqueId } from "../util/uniqueId";
|
||||||
import { loge } from "../util/log";
|
import { loge } from "../util/log";
|
||||||
|
const PROP_CONSIST = 1;
|
||||||
|
const PROP_INCONSIST = 2;
|
||||||
export function Property(target, propKey) {
|
export function Property(target, propKey) {
|
||||||
Reflect.defineMetadata(propKey, true, target);
|
Reflect.defineMetadata(propKey, PROP_CONSIST, target);
|
||||||
|
}
|
||||||
|
export function InconsistProperty(target, propKey) {
|
||||||
|
Reflect.defineMetadata(propKey, PROP_INCONSIST, target);
|
||||||
}
|
}
|
||||||
export class View {
|
export class View {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -35,7 +40,10 @@ export class View {
|
|||||||
set: (target, p, v, receiver) => {
|
set: (target, p, v, receiver) => {
|
||||||
const oldV = Reflect.get(target, p, receiver);
|
const oldV = Reflect.get(target, p, receiver);
|
||||||
const ret = Reflect.set(target, p, v, receiver);
|
const ret = Reflect.set(target, p, v, receiver);
|
||||||
if (Reflect.getMetadata(p, target) && oldV !== v) {
|
if (Reflect.getMetadata(p, target) === PROP_CONSIST && oldV !== v) {
|
||||||
|
receiver.onPropertyChanged(p.toString(), oldV, v);
|
||||||
|
}
|
||||||
|
else if (Reflect.getMetadata(p, target) === PROP_INCONSIST) {
|
||||||
receiver.onPropertyChanged(p.toString(), oldV, v);
|
receiver.onPropertyChanged(p.toString(), oldV, v);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -37,6 +37,19 @@ export function Property(target: View, propKey: string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function InconsistProperty(target: Object, propKey: string) {
|
||||||
|
Object.defineProperty(target, propKey, {
|
||||||
|
get: function () {
|
||||||
|
return Reflect.get(this, `__prop__${propKey}`, this)
|
||||||
|
},
|
||||||
|
set: function (v) {
|
||||||
|
const oldV = Reflect.get(this, `__prop__${propKey}`, this)
|
||||||
|
Reflect.set(this, `__prop__${propKey}`, v, this)
|
||||||
|
Reflect.apply(this.onPropertyChanged, this, [propKey, oldV, v])
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export type NativeViewModel = {
|
export type NativeViewModel = {
|
||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
|
@ -22,8 +22,15 @@ import { LayoutConfig } from '../util/layoutconfig'
|
|||||||
import { IAnimation } from "./animation";
|
import { IAnimation } from "./animation";
|
||||||
import { FlexConfig } from "../util/flexbox";
|
import { FlexConfig } from "../util/flexbox";
|
||||||
|
|
||||||
|
const PROP_CONSIST = 1;
|
||||||
|
const PROP_INCONSIST = 2;
|
||||||
|
|
||||||
export function Property(target: Object, propKey: string) {
|
export function Property(target: Object, propKey: string) {
|
||||||
Reflect.defineMetadata(propKey, true, target)
|
Reflect.defineMetadata(propKey, PROP_CONSIST, target)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InconsistProperty(target: Object, propKey: string) {
|
||||||
|
Reflect.defineMetadata(propKey, PROP_INCONSIST, target)
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NativeViewModel = {
|
export type NativeViewModel = {
|
||||||
@ -118,7 +125,9 @@ export abstract class View implements Modeling {
|
|||||||
set: (target, p, v, receiver) => {
|
set: (target, p, v, receiver) => {
|
||||||
const oldV = Reflect.get(target, p, receiver)
|
const oldV = Reflect.get(target, p, receiver)
|
||||||
const ret = Reflect.set(target, p, v, receiver)
|
const ret = Reflect.set(target, p, v, receiver)
|
||||||
if (Reflect.getMetadata(p, target) && oldV !== v) {
|
if (Reflect.getMetadata(p, target) === PROP_CONSIST && oldV !== v) {
|
||||||
|
receiver.onPropertyChanged(p.toString(), oldV, v)
|
||||||
|
} else if (Reflect.getMetadata(p, target) === PROP_INCONSIST) {
|
||||||
receiver.onPropertyChanged(p.toString(), oldV, v)
|
receiver.onPropertyChanged(p.toString(), oldV, v)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { View, Property } from "../ui/view";
|
import { View, Property, InconsistProperty } from "../ui/view";
|
||||||
import { Color } from "../util/color";
|
import { Color } from "../util/color";
|
||||||
import { Gravity } from "../util/gravity";
|
import { Gravity } from "../util/gravity";
|
||||||
import { BridgeContext } from "../runtime/global";
|
import { BridgeContext } from "../runtime/global";
|
||||||
@ -21,7 +21,7 @@ import { layoutConfig } from "../util/index.util";
|
|||||||
|
|
||||||
export class Input extends View {
|
export class Input extends View {
|
||||||
|
|
||||||
@Property
|
@InconsistProperty
|
||||||
text?: string
|
text?: string
|
||||||
|
|
||||||
@Property
|
@Property
|
||||||
@ -53,7 +53,7 @@ export class Input extends View {
|
|||||||
|
|
||||||
@Property
|
@Property
|
||||||
maxLength?: number
|
maxLength?: number
|
||||||
|
|
||||||
@Property
|
@Property
|
||||||
password?: boolean
|
password?: boolean
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { View, Property } from "../ui/view";
|
import { View, Property, InconsistProperty } from "../ui/view";
|
||||||
import { Color } from "../util/color";
|
import { Color } from "../util/color";
|
||||||
import { layoutConfig } from "../util/index.util";
|
import { layoutConfig } from "../util/index.util";
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ export class Switch extends View {
|
|||||||
/**
|
/**
|
||||||
* True is on ,false is off,defalut is off.
|
* True is on ,false is off,defalut is off.
|
||||||
*/
|
*/
|
||||||
@Property
|
@InconsistProperty
|
||||||
state?: boolean
|
state?: boolean
|
||||||
/**
|
/**
|
||||||
* Switch change callback
|
* Switch change callback
|
||||||
|
Reference in New Issue
Block a user