android&iOS:create context set this to undefined

This commit is contained in:
pengfei.zhou 2020-01-08 20:18:19 +08:00 committed by osborn
parent cdaebe46cd
commit 0087c5bda4
10 changed files with 67 additions and 5 deletions

View File

@ -222,7 +222,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
} }
private String packageContextScript(String contextId, String content) { private String packageContextScript(String contextId, String content) {
return String.format(DoricConstant.TEMPLATE_CONTEXT_CREATE, content, contextId, contextId, contextId); return String.format(DoricConstant.TEMPLATE_CONTEXT_CREATE, content, contextId, contextId);
} }
private String packageModuleScript(String moduleName, String content) { private String packageModuleScript(String moduleName, String content) {

View File

@ -38,7 +38,7 @@ public class DoricConstant {
public static final String TEMPLATE_CONTEXT_CREATE = "Reflect.apply(" + public static final String TEMPLATE_CONTEXT_CREATE = "Reflect.apply(" +
"function(doric,context,Entry,require,exports){" + "\n" + "function(doric,context,Entry,require,exports){" + "\n" +
"%s" + "\n" + "%s" + "\n" +
"},doric.jsObtainContext(\"%s\"),[" + "},undefined,[" +
"undefined," + "undefined," +
"doric.jsObtainContext(\"%s\")," + "doric.jsObtainContext(\"%s\")," +
"doric.jsObtainEntry(\"%s\")," + "doric.jsObtainEntry(\"%s\")," +

View File

@ -150,7 +150,7 @@ - (JSValue *)invokeDoricMethod:(NSString *)method argumentsArray:(NSArray *)args
} }
- (NSString *)packageContextScript:(NSString *)contextId content:(NSString *)content { - (NSString *)packageContextScript:(NSString *)contextId content:(NSString *)content {
NSString *ret = [NSString stringWithFormat:TEMPLATE_CONTEXT_CREATE, content, contextId, contextId, contextId]; NSString *ret = [NSString stringWithFormat:TEMPLATE_CONTEXT_CREATE, content, contextId, contextId];
return ret; return ret;
} }

View File

@ -38,7 +38,7 @@
NSString *const TEMPLATE_CONTEXT_CREATE = @"Reflect.apply(" NSString *const TEMPLATE_CONTEXT_CREATE = @"Reflect.apply("
"function(doric,context,Entry,require,exports){" "\n" "function(doric,context,Entry,require,exports){" "\n"
"%@" "\n" "%@" "\n"
"},doric.jsObtainContext(\"%@\"),[" "},undefined,["
"undefined," "undefined,"
"doric.jsObtainContext(\"%@\")," "doric.jsObtainContext(\"%@\"),"
"doric.jsObtainEntry(\"%@\")," "doric.jsObtainEntry(\"%@\"),"

View File

@ -2081,6 +2081,25 @@ function animate(context) {
} }
} }
function notification(context) {
return {
publish: (args) => {
if (args.data !== undefined) {
args.data = JSON.stringify(args.data);
}
return context.notification.publish(args);
},
subscribe: (args) => {
args.callback = context.function2Id(args.callback);
return context.notification.subscribe(args);
},
unsubscribe: (subscribeId) => {
context.removeFuncById(subscribeId);
return context.notification.unsubscribe({ subscribeId });
}
};
}
class Observable { class Observable {
constructor(provider, clz) { constructor(provider, clz) {
this.observers = new Set; this.observers = new Set;
@ -2224,6 +2243,7 @@ exports.modal = modal;
exports.navbar = navbar; exports.navbar = navbar;
exports.navigator = navigator; exports.navigator = navigator;
exports.network = network; exports.network = network;
exports.notification = notification;
exports.obj2Model = obj2Model; exports.obj2Model = obj2Model;
exports.popover = popover; exports.popover = popover;
exports.pullable = pullable; exports.pullable = pullable;

View File

@ -3540,6 +3540,25 @@ function animate(context) {
} }
} }
function notification(context) {
return {
publish: (args) => {
if (args.data !== undefined) {
args.data = JSON.stringify(args.data);
}
return context.notification.publish(args);
},
subscribe: (args) => {
args.callback = context.function2Id(args.callback);
return context.notification.subscribe(args);
},
unsubscribe: (subscribeId) => {
context.removeFuncById(subscribeId);
return context.notification.unsubscribe({ subscribeId });
}
};
}
class Observable { class Observable {
constructor(provider, clz) { constructor(provider, clz) {
this.observers = new Set; this.observers = new Set;
@ -3789,6 +3808,7 @@ exports.modal = modal;
exports.navbar = navbar; exports.navbar = navbar;
exports.navigator = navigator; exports.navigator = navigator;
exports.network = network; exports.network = network;
exports.notification = notification;
exports.obj2Model = obj2Model; exports.obj2Model = obj2Model;
exports.popover = popover; exports.popover = popover;
exports.pullable = pullable; exports.pullable = pullable;

20
doric-js/index.d.ts vendored
View File

@ -64,6 +64,7 @@ declare module 'doric/lib/src/native/index.native' {
export * from 'doric/lib/src/native/storage'; export * from 'doric/lib/src/native/storage';
export * from 'doric/lib/src/native/popover'; export * from 'doric/lib/src/native/popover';
export * from 'doric/lib/src/native/animate'; export * from 'doric/lib/src/native/animate';
export * from 'doric/lib/src/native/notification';
} }
declare module 'doric/lib/src/util/index.util' { declare module 'doric/lib/src/util/index.util' {
@ -792,6 +793,25 @@ declare module 'doric/lib/src/native/animate' {
}) => Promise<any>; }) => Promise<any>;
} }
declare module 'doric/lib/src/native/notification' {
import { BridgeContext } from "doric/lib/src/runtime/global";
export function notification(context: BridgeContext): {
publish: (args: {
biz: string;
name: string;
data?: object | undefined;
androidSystem?: boolean | undefined;
}) => Promise<any>;
subscribe: (args: {
biz: string;
name: string;
callback: (data?: any) => void;
androidSystem?: boolean | undefined;
}) => Promise<string>;
unsubscribe: (subscribeId: string) => Promise<any>;
};
}
declare module 'doric/lib/src/util/color' { declare module 'doric/lib/src/util/color' {
import { Modeling } from "doric/lib/src/util/types"; import { Modeling } from "doric/lib/src/util/types";
/** /**

View File

@ -5,3 +5,4 @@ export * from './network';
export * from './storage'; export * from './storage';
export * from './popover'; export * from './popover';
export * from './animate'; export * from './animate';
export * from './notification';

View File

@ -20,3 +20,4 @@ export * from './network';
export * from './storage'; export * from './storage';
export * from './popover'; export * from './popover';
export * from './animate'; export * from './animate';
export * from './notification';

View File

@ -9,7 +9,7 @@ export declare function notification(context: BridgeContext): {
subscribe: (args: { subscribe: (args: {
biz: string; biz: string;
name: string; name: string;
callback: (data?: object | undefined) => void; callback: (data?: any) => void;
androidSystem?: boolean | undefined; androidSystem?: boolean | undefined;
}) => Promise<string>; }) => Promise<string>;
unsubscribe: (subscribeId: string) => Promise<any>; unsubscribe: (subscribeId: string) => Promise<any>;