提交 e5285d29 编写于 作者: fxy060608's avatar fxy060608

feat(runtime): add uni.$on,uni.$once,uni.$off,uni.$emit

上级 f482d453
...@@ -40,7 +40,7 @@ const camelize = cached((str) => { ...@@ -40,7 +40,7 @@ const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '') return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
}); });
const SYNC_API_RE = /getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const SYNC_API_RE = /^\$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/; const CONTEXT_API_RE = /^create|Manager$/;
...@@ -256,6 +256,22 @@ TODOS.forEach(function (name) { ...@@ -256,6 +256,22 @@ TODOS.forEach(function (name) {
todoApis[name] = createTodoApi(name); todoApis[name] = createTodoApi(name);
}); });
const Emitter = new Vue();
const $on = Emitter.$on.bind(Emitter);
const $off = Emitter.$off.bind(Emitter);
const $once = Emitter.$once.bind(Emitter);
const $emit = Emitter.$emit.bind(Emitter);
var eventApi = /*#__PURE__*/Object.freeze({
$on: $on,
$off: $off,
$once: $once,
$emit: $emit
});
function wrapper$1 (webview) { function wrapper$1 (webview) {
webview.$processed = true; webview.$processed = true;
...@@ -1142,6 +1158,9 @@ if (typeof Proxy !== 'undefined') { ...@@ -1142,6 +1158,9 @@ if (typeof Proxy !== 'undefined') {
if (api[name]) { if (api[name]) {
return promisify(name, api[name]) return promisify(name, api[name])
} }
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(wx, name) && !hasOwn(protocols, name)) { if (!hasOwn(wx, name) && !hasOwn(protocols, name)) {
return return
} }
...@@ -1151,6 +1170,10 @@ if (typeof Proxy !== 'undefined') { ...@@ -1151,6 +1170,10 @@ if (typeof Proxy !== 'undefined') {
} else { } else {
uni.upx2px = upx2px; uni.upx2px = upx2px;
Object.keys(eventApi).forEach(name => {
uni[name] = eventApi[name];
});
Object.keys(api).forEach(name => { Object.keys(api).forEach(name => {
uni[name] = promisify(name, api[name]); uni[name] = promisify(name, api[name]);
}); });
...@@ -1162,6 +1185,12 @@ if (typeof Proxy !== 'undefined') { ...@@ -1162,6 +1185,12 @@ if (typeof Proxy !== 'undefined') {
}); });
} }
{
if (typeof global !== 'undefined') {
global.UniEmitter = eventApi;
}
}
wx.createApp = createApp; wx.createApp = createApp;
wx.createPage = createPage; wx.createPage = createPage;
wx.createComponent = createComponent; wx.createComponent = createComponent;
......
...@@ -40,7 +40,7 @@ const camelize = cached((str) => { ...@@ -40,7 +40,7 @@ const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '') return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
}); });
const SYNC_API_RE = /getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const SYNC_API_RE = /^\$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/; const CONTEXT_API_RE = /^create|Manager$/;
...@@ -656,6 +656,22 @@ var extraApi = /*#__PURE__*/Object.freeze({ ...@@ -656,6 +656,22 @@ var extraApi = /*#__PURE__*/Object.freeze({
getProvider: getProvider getProvider: getProvider
}); });
const Emitter = new Vue();
const $on = Emitter.$on.bind(Emitter);
const $off = Emitter.$off.bind(Emitter);
const $once = Emitter.$once.bind(Emitter);
const $emit = Emitter.$emit.bind(Emitter);
var eventApi = /*#__PURE__*/Object.freeze({
$on: $on,
$off: $off,
$once: $once,
$emit: $emit
});
function setStorageSync (key, data) { function setStorageSync (key, data) {
return my.setStorageSync({ return my.setStorageSync({
key, key,
...@@ -1667,6 +1683,9 @@ if (typeof Proxy !== 'undefined') { ...@@ -1667,6 +1683,9 @@ if (typeof Proxy !== 'undefined') {
return promisify(name, todoApis[name]) return promisify(name, todoApis[name])
} }
} }
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(my, name) && !hasOwn(protocols, name)) { if (!hasOwn(my, name) && !hasOwn(protocols, name)) {
return return
} }
...@@ -1685,6 +1704,10 @@ if (typeof Proxy !== 'undefined') { ...@@ -1685,6 +1704,10 @@ if (typeof Proxy !== 'undefined') {
}); });
} }
Object.keys(eventApi).forEach(name => {
uni[name] = eventApi[name];
});
Object.keys(api).forEach(name => { Object.keys(api).forEach(name => {
uni[name] = promisify(name, api[name]); uni[name] = promisify(name, api[name]);
}); });
......
...@@ -40,7 +40,7 @@ const camelize = cached((str) => { ...@@ -40,7 +40,7 @@ const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '') return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
}); });
const SYNC_API_RE = /getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const SYNC_API_RE = /^\$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/; const CONTEXT_API_RE = /^create|Manager$/;
...@@ -413,6 +413,22 @@ var extraApi = /*#__PURE__*/Object.freeze({ ...@@ -413,6 +413,22 @@ var extraApi = /*#__PURE__*/Object.freeze({
getProvider: getProvider getProvider: getProvider
}); });
const Emitter = new Vue();
const $on = Emitter.$on.bind(Emitter);
const $off = Emitter.$off.bind(Emitter);
const $once = Emitter.$once.bind(Emitter);
const $emit = Emitter.$emit.bind(Emitter);
var eventApi = /*#__PURE__*/Object.freeze({
$on: $on,
$off: $off,
$once: $once,
$emit: $emit
});
function requestPayment (params) { function requestPayment (params) {
let parseError = false; let parseError = false;
if (typeof params.orderInfo === 'string') { if (typeof params.orderInfo === 'string') {
...@@ -1286,6 +1302,9 @@ if (typeof Proxy !== 'undefined') { ...@@ -1286,6 +1302,9 @@ if (typeof Proxy !== 'undefined') {
return promisify(name, todoApis[name]) return promisify(name, todoApis[name])
} }
} }
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(swan, name) && !hasOwn(protocols, name)) { if (!hasOwn(swan, name) && !hasOwn(protocols, name)) {
return return
} }
...@@ -1304,6 +1323,10 @@ if (typeof Proxy !== 'undefined') { ...@@ -1304,6 +1323,10 @@ if (typeof Proxy !== 'undefined') {
}); });
} }
Object.keys(eventApi).forEach(name => {
uni[name] = eventApi[name];
});
Object.keys(api).forEach(name => { Object.keys(api).forEach(name => {
uni[name] = promisify(name, api[name]); uni[name] = promisify(name, api[name]);
}); });
......
...@@ -40,7 +40,7 @@ const camelize = cached((str) => { ...@@ -40,7 +40,7 @@ const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '') return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
}); });
const SYNC_API_RE = /getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const SYNC_API_RE = /^\$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/; const CONTEXT_API_RE = /^create|Manager$/;
...@@ -474,6 +474,22 @@ var extraApi = /*#__PURE__*/Object.freeze({ ...@@ -474,6 +474,22 @@ var extraApi = /*#__PURE__*/Object.freeze({
getProvider: getProvider getProvider: getProvider
}); });
const Emitter = new Vue();
const $on = Emitter.$on.bind(Emitter);
const $off = Emitter.$off.bind(Emitter);
const $once = Emitter.$once.bind(Emitter);
const $emit = Emitter.$emit.bind(Emitter);
var eventApi = /*#__PURE__*/Object.freeze({
$on: $on,
$off: $off,
$once: $once,
$emit: $emit
});
var api = /*#__PURE__*/Object.freeze({ var api = /*#__PURE__*/Object.freeze({
...@@ -1361,6 +1377,9 @@ if (typeof Proxy !== 'undefined') { ...@@ -1361,6 +1377,9 @@ if (typeof Proxy !== 'undefined') {
return promisify(name, todoApis[name]) return promisify(name, todoApis[name])
} }
} }
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(tt, name) && !hasOwn(protocols, name)) { if (!hasOwn(tt, name) && !hasOwn(protocols, name)) {
return return
} }
...@@ -1379,6 +1398,10 @@ if (typeof Proxy !== 'undefined') { ...@@ -1379,6 +1398,10 @@ if (typeof Proxy !== 'undefined') {
}); });
} }
Object.keys(eventApi).forEach(name => {
uni[name] = eventApi[name];
});
Object.keys(api).forEach(name => { Object.keys(api).forEach(name => {
uni[name] = promisify(name, api[name]); uni[name] = promisify(name, api[name]);
}); });
......
...@@ -40,7 +40,7 @@ const camelize = cached((str) => { ...@@ -40,7 +40,7 @@ const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '') return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
}); });
const SYNC_API_RE = /getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const SYNC_API_RE = /^\$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/; const CONTEXT_API_RE = /^create|Manager$/;
...@@ -326,6 +326,22 @@ var extraApi = /*#__PURE__*/Object.freeze({ ...@@ -326,6 +326,22 @@ var extraApi = /*#__PURE__*/Object.freeze({
getProvider: getProvider getProvider: getProvider
}); });
const Emitter = new Vue();
const $on = Emitter.$on.bind(Emitter);
const $off = Emitter.$off.bind(Emitter);
const $once = Emitter.$once.bind(Emitter);
const $emit = Emitter.$emit.bind(Emitter);
var eventApi = /*#__PURE__*/Object.freeze({
$on: $on,
$off: $off,
$once: $once,
$emit: $emit
});
var api = /*#__PURE__*/Object.freeze({ var api = /*#__PURE__*/Object.freeze({
...@@ -1121,6 +1137,9 @@ if (typeof Proxy !== 'undefined') { ...@@ -1121,6 +1137,9 @@ if (typeof Proxy !== 'undefined') {
return promisify(name, todoApis[name]) return promisify(name, todoApis[name])
} }
} }
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(wx, name) && !hasOwn(protocols, name)) { if (!hasOwn(wx, name) && !hasOwn(protocols, name)) {
return return
} }
...@@ -1139,6 +1158,10 @@ if (typeof Proxy !== 'undefined') { ...@@ -1139,6 +1158,10 @@ if (typeof Proxy !== 'undefined') {
}); });
} }
Object.keys(eventApi).forEach(name => {
uni[name] = eventApi[name];
});
Object.keys(api).forEach(name => { Object.keys(api).forEach(name => {
uni[name] = promisify(name, api[name]); uni[name] = promisify(name, api[name]);
}); });
......
...@@ -2,7 +2,7 @@ import { ...@@ -2,7 +2,7 @@ import {
isFn isFn
} from 'uni-shared' } from 'uni-shared'
const SYNC_API_RE = /getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/ const SYNC_API_RE = /^\$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
const CONTEXT_API_RE = /^create|Manager$/ const CONTEXT_API_RE = /^create|Manager$/
......
export * from '../service/api/event'
...@@ -16,6 +16,8 @@ import todoApi from './todo' ...@@ -16,6 +16,8 @@ import todoApi from './todo'
import * as extraApi from './extra' import * as extraApi from './extra'
import * as eventApi from './event'
import * as api from 'uni-platform/service/api/index.js' import * as api from 'uni-platform/service/api/index.js'
import { import {
...@@ -59,6 +61,9 @@ if (typeof Proxy !== 'undefined') { ...@@ -59,6 +61,9 @@ if (typeof Proxy !== 'undefined') {
return promisify(name, todoApi[name]) return promisify(name, todoApi[name])
} }
} }
if (eventApi[name]) {
return eventApi[name]
}
if (!hasOwn(__GLOBAL__, name) && !hasOwn(protocols, name)) { if (!hasOwn(__GLOBAL__, name) && !hasOwn(protocols, name)) {
return return
} }
...@@ -77,6 +82,10 @@ if (typeof Proxy !== 'undefined') { ...@@ -77,6 +82,10 @@ if (typeof Proxy !== 'undefined') {
}) })
} }
Object.keys(eventApi).forEach(name => {
uni[name] = eventApi[name]
})
Object.keys(api).forEach(name => { Object.keys(api).forEach(name => {
uni[name] = promisify(name, api[name]) uni[name] = promisify(name, api[name])
}) })
...@@ -88,6 +97,12 @@ if (typeof Proxy !== 'undefined') { ...@@ -88,6 +97,12 @@ if (typeof Proxy !== 'undefined') {
}) })
} }
if (__PLATFORM__ === 'app-plus') {
if (typeof global !== 'undefined') {
global.UniEmitter = eventApi
}
}
__GLOBAL__.createApp = createApp __GLOBAL__.createApp = createApp
__GLOBAL__.createPage = createPage __GLOBAL__.createPage = createPage
__GLOBAL__.createComponent = createComponent __GLOBAL__.createComponent = createComponent
......
import Vue from 'vue'
const Emitter = new Vue()
export const $on = Emitter.$on.bind(Emitter)
export const $off = Emitter.$off.bind(Emitter)
export const $once = Emitter.$once.bind(Emitter)
export const $emit = Emitter.$emit.bind(Emitter)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册