diff --git a/doric-android/doric/src/main/java/pub/doric/engine/DoricJSEngine.java b/doric-android/doric/src/main/java/pub/doric/engine/DoricJSEngine.java index 336c5c2d..1f9e9e70 100644 --- a/doric-android/doric/src/main/java/pub/doric/engine/DoricJSEngine.java +++ b/doric-android/doric/src/main/java/pub/doric/engine/DoricJSEngine.java @@ -222,7 +222,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time } 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) { diff --git a/doric-android/doric/src/main/java/pub/doric/utils/DoricConstant.java b/doric-android/doric/src/main/java/pub/doric/utils/DoricConstant.java index efeb131f..14fcb0f0 100644 --- a/doric-android/doric/src/main/java/pub/doric/utils/DoricConstant.java +++ b/doric-android/doric/src/main/java/pub/doric/utils/DoricConstant.java @@ -38,7 +38,7 @@ public class DoricConstant { public static final String TEMPLATE_CONTEXT_CREATE = "Reflect.apply(" + "function(doric,context,Entry,require,exports){" + "\n" + "%s" + "\n" + - "},doric.jsObtainContext(\"%s\"),[" + + "},undefined,[" + "undefined," + "doric.jsObtainContext(\"%s\")," + "doric.jsObtainEntry(\"%s\")," + diff --git a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m index 3484230a..6a3707a8 100644 --- a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -150,7 +150,7 @@ - (JSValue *)invokeDoricMethod:(NSString *)method argumentsArray:(NSArray *)args } - (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; } diff --git a/doric-iOS/Pod/Classes/Util/DoricConstant.m b/doric-iOS/Pod/Classes/Util/DoricConstant.m index b7b30543..a0022b03 100644 --- a/doric-iOS/Pod/Classes/Util/DoricConstant.m +++ b/doric-iOS/Pod/Classes/Util/DoricConstant.m @@ -38,7 +38,7 @@ NSString *const TEMPLATE_CONTEXT_CREATE = @"Reflect.apply(" "function(doric,context,Entry,require,exports){" "\n" "%@" "\n" - "},doric.jsObtainContext(\"%@\"),[" + "},undefined,[" "undefined," "doric.jsObtainContext(\"%@\")," "doric.jsObtainEntry(\"%@\")," diff --git a/doric-js/bundle/doric-lib.js b/doric-js/bundle/doric-lib.js index 18114d4a..aae6e2b3 100644 --- a/doric-js/bundle/doric-lib.js +++ b/doric-js/bundle/doric-lib.js @@ -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 { constructor(provider, clz) { this.observers = new Set; @@ -2224,6 +2243,7 @@ exports.modal = modal; exports.navbar = navbar; exports.navigator = navigator; exports.network = network; +exports.notification = notification; exports.obj2Model = obj2Model; exports.popover = popover; exports.pullable = pullable; diff --git a/doric-js/bundle/doric-vm.js b/doric-js/bundle/doric-vm.js index 993e56c9..0f2827b1 100644 --- a/doric-js/bundle/doric-vm.js +++ b/doric-js/bundle/doric-vm.js @@ -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 { constructor(provider, clz) { this.observers = new Set; @@ -3789,6 +3808,7 @@ exports.modal = modal; exports.navbar = navbar; exports.navigator = navigator; exports.network = network; +exports.notification = notification; exports.obj2Model = obj2Model; exports.popover = popover; exports.pullable = pullable; diff --git a/doric-js/index.d.ts b/doric-js/index.d.ts index b72a7ae3..ce64e1d6 100644 --- a/doric-js/index.d.ts +++ b/doric-js/index.d.ts @@ -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/popover'; export * from 'doric/lib/src/native/animate'; + export * from 'doric/lib/src/native/notification'; } declare module 'doric/lib/src/util/index.util' { @@ -792,6 +793,25 @@ declare module 'doric/lib/src/native/animate' { }) => Promise; } +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; + subscribe: (args: { + biz: string; + name: string; + callback: (data?: any) => void; + androidSystem?: boolean | undefined; + }) => Promise; + unsubscribe: (subscribeId: string) => Promise; + }; +} + declare module 'doric/lib/src/util/color' { import { Modeling } from "doric/lib/src/util/types"; /** diff --git a/doric-js/lib/src/native/index.native.d.ts b/doric-js/lib/src/native/index.native.d.ts index e1500e52..c4c27466 100644 --- a/doric-js/lib/src/native/index.native.d.ts +++ b/doric-js/lib/src/native/index.native.d.ts @@ -5,3 +5,4 @@ export * from './network'; export * from './storage'; export * from './popover'; export * from './animate'; +export * from './notification'; diff --git a/doric-js/lib/src/native/index.native.js b/doric-js/lib/src/native/index.native.js index bbd8b923..fe806418 100644 --- a/doric-js/lib/src/native/index.native.js +++ b/doric-js/lib/src/native/index.native.js @@ -20,3 +20,4 @@ export * from './network'; export * from './storage'; export * from './popover'; export * from './animate'; +export * from './notification'; diff --git a/doric-js/lib/src/native/notification.d.ts b/doric-js/lib/src/native/notification.d.ts index f1cb6b7d..4d96750c 100644 --- a/doric-js/lib/src/native/notification.d.ts +++ b/doric-js/lib/src/native/notification.d.ts @@ -9,7 +9,7 @@ export declare function notification(context: BridgeContext): { subscribe: (args: { biz: string; name: string; - callback: (data?: object | undefined) => void; + callback: (data?: any) => void; androidSystem?: boolean | undefined; }) => Promise; unsubscribe: (subscribeId: string) => Promise;