web: export notification

This commit is contained in:
王劲鹏 2020-01-09 19:38:23 +08:00 committed by osborn
parent 15e292b894
commit 42d8258309
2 changed files with 32 additions and 1 deletions

View File

@ -1312,6 +1312,17 @@ var doric = (function (exports) {
register(instance) { register(instance) {
this.entity = instance; this.entity = instance;
} }
function2Id(func) {
const functionId = uniqueId('function');
this.callbacks.set(functionId, {
resolve: func,
reject: () => { loge("This should not be called"); }
});
return functionId;
}
removeFuncById(funcId) {
this.callbacks.delete(funcId);
}
} }
const gContexts = new Map; const gContexts = new Map;
const gModules = new Map; const gModules = new Map;
@ -3610,6 +3621,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;
@ -3753,6 +3783,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;

File diff suppressed because one or more lines are too long