feat:Add InconsistProperty decorator because sometimes the property in js side cannot be consist with natiive side
This commit is contained in:
@@ -203,8 +203,10 @@ global.nativeLog = (type, msg) => {
|
||||
};
|
||||
global.nativeRequire = () => {
|
||||
console.error("Do not call nativeRequire here");
|
||||
return false;
|
||||
};
|
||||
global.nativeBridge = () => {
|
||||
console.error("Do not call nativeBridge here");
|
||||
return false;
|
||||
};
|
||||
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 { FlexConfig } from "../util/flexbox";
|
||||
export declare function Property(target: Object, propKey: string): void;
|
||||
export declare function InconsistProperty(target: Object, propKey: string): void;
|
||||
export declare type NativeViewModel = {
|
||||
id: string;
|
||||
type: string;
|
||||
|
@@ -10,8 +10,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
import { obj2Model } from "../util/types";
|
||||
import { uniqueId } from "../util/uniqueId";
|
||||
import { loge } from "../util/log";
|
||||
const PROP_CONSIST = 1;
|
||||
const PROP_INCONSIST = 2;
|
||||
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 {
|
||||
constructor() {
|
||||
@@ -35,7 +40,10 @@ export class View {
|
||||
set: (target, p, v, receiver) => {
|
||||
const oldV = Reflect.get(target, p, 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);
|
||||
}
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user