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

chore: merge

......@@ -16,10 +16,11 @@
"freeze": false,
"name": "serviceContext",
"format": "iife",
"banner": "export function createServiceContext(weex, plus, instanceContext){\nconst Vue = instanceContext.Vue;\nlet setTimeout = instanceContext.setTimeout;\nlet clearTimeout = instanceContext.clearTimeout;\nlet setInterval = instanceContext.setInterval;\nlet clearInterval = instanceContext.clearInterval;\nconst __uniConfig = instanceContext.__uniConfig;\nconst __uniRoutes = instanceContext.__uniRoutes;\n",
"banner": "export function createServiceContext(weex, plus, instanceContext){\nconst Vue = instanceContext.Vue;\nlet setTimeout = instanceContext.setTimeout;\nlet clearTimeout = instanceContext.clearTimeout;\nlet setInterval = instanceContext.setInterval;\nlet clearInterval = instanceContext.clearInterval;\nconst __uniConfig = instanceContext.__uniConfig;\nconst __uniRoutes = instanceContext.__uniRoutes;\nconst VueShared = instanceContext.VueShared;\n",
"footer": "const uni = serviceContext.uni;\nconst getApp = serviceContext.getApp;\nconst getCurrentPages = serviceContext.getCurrentPages;\nconst UniServiceJSBridge = serviceContext.UniServiceJSBridge;\nreturn serviceContext;\n}",
"globals": {
"vue": "Vue"
"vue": "Vue",
"@vue/shared": "VueShared"
},
"inlineDynamicImports": true
},
......@@ -36,7 +37,7 @@
"__UNI_FEATURE_I18N_ZH_HANS__": "true",
"__UNI_FEATURE_I18N_ZH_HANT__": "true"
},
"external": ["vue"],
"external": ["vue", "@vue/shared"],
"replaceAfterBundled": {
"__VUE__": "vue"
}
......
[
{
"input": {
"src/nvue/bridge.ts": ["dist/bridge.js"]
}
}
]
const E = function () {
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
};
E.prototype = {
on: function (name, callback, ctx) {
var e = this.e || (this.e = {});
(e[name] || (e[name] = [])).push({
fn: callback,
ctx: ctx,
});
return this;
},
once: function (name, callback, ctx) {
var self = this;
function listener() {
self.off(name, listener);
callback.apply(ctx, arguments);
}
listener._ = callback;
return this.on(name, listener, ctx);
},
emit: function (name) {
var data = [].slice.call(arguments, 1);
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
var i = 0;
var len = evtArr.length;
for (i; i < len; i++) {
evtArr[i].fn.apply(evtArr[i].ctx, data);
}
return this;
},
off: function (name, callback) {
var e = this.e || (this.e = {});
var evts = e[name];
var liveEvents = [];
if (evts && callback) {
for (var i = 0, len = evts.length; i < len; i++) {
if (evts[i].fn !== callback && evts[i].fn._ !== callback)
liveEvents.push(evts[i]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
liveEvents.length ? (e[name] = liveEvents) : delete e[name];
return this;
},
};
var E$1 = E;
function initBridge(subscribeNamespace) {
const emitter = new E$1();
return {
on(event, callback) {
return emitter.on(event, callback);
},
once(event, callback) {
return emitter.once(event, callback);
},
off(event, callback) {
return emitter.off(event, callback);
},
emit(event, ...args) {
return emitter.emit(event, ...args);
},
subscribe(event, callback, once = false) {
emitter[once ? 'once' : 'on'](`${subscribeNamespace}.${event}`, callback);
},
unsubscribe(event, callback) {
emitter.off(`${subscribeNamespace}.${event}`, callback);
},
subscribeHandler(event, args, pageId) {
emitter.emit(`${subscribeNamespace}.${event}`, args, pageId);
},
};
}
const UniViewJSBridge = initBridge('nvue');
export { UniViewJSBridge };
export function initComponents(uni, Vue, weex) {
var components = function(vue) {
export function initComponents({ uni, Vue, weex, plus, BroadcastChannel }) {
var components = function(vue, shared) {
"use strict";
const OPEN_TYPES = [
"navigate",
......@@ -81,18 +81,16 @@ export function initComponents(uni, Vue, weex) {
}
};
}
const hasOwnProperty = Object.prototype.hasOwnProperty;
const hasOwn = (val, key) => hasOwnProperty.call(val, key);
function useHoverClass(props) {
if (props.hoverClass && props.hoverClass !== "none") {
const hoverAttrs = { hoverClass: props.hoverClass };
if (hasOwn(props, "hoverStartTime")) {
if (shared.hasOwn(props, "hoverStartTime")) {
hoverAttrs.hoverStartTime = props.hoverStartTime;
}
if (hasOwn(props, "hoverStayTime")) {
if (shared.hasOwn(props, "hoverStayTime")) {
hoverAttrs.hoverStayTime = props.hoverStayTime;
}
if (hasOwn(props, "hoverStopPropagation")) {
if (shared.hasOwn(props, "hoverStopPropagation")) {
hoverAttrs.hoverStopPropagation = props.hoverStopPropagation;
}
return hoverAttrs;
......@@ -124,6 +122,6 @@ export function initComponents(uni, Vue, weex) {
Navigator
};
return index;
}(Vue);
}(Vue, VueShared);
return components;
}
import { initBridge } from '@dcloudio/uni-core'
export const UniViewJSBridge = initBridge('nvue')
......@@ -2,8 +2,21 @@ import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
function resolve(file: string) {
return path.resolve(__dirname, file)
}
export default defineConfig({
root: __dirname,
resolve: {
alias: [
{
find: '@dcloudio/uni-core',
replacement: resolve('../uni-core/src'),
},
],
},
build: {
minify: false,
lib: {
......@@ -12,15 +25,17 @@ export default defineConfig({
formats: ['iife'],
},
rollupOptions: {
external: ['uni', 'vue', 'weex'],
external: ['uni', 'vue', 'weex', '@vue/shared'],
output: {
banner: 'export function initComponents(uni, Vue, weex) {',
banner:
'export function initComponents({uni,Vue,weex,plus,BroadcastChannel}) {',
footer: 'return components\n}',
entryFileNames: 'components.js',
globals: {
uni: 'uni',
vue: 'Vue',
weex: 'weex',
'@vue/shared': 'VueShared',
},
},
},
......
// TODO 等待 vue3 的兼容模式自带emitter
import E from './TinyEmitter'
export function initBridge(
subscribeNamespace: 'service' | 'view'
subscribeNamespace: 'service' | 'view' | 'nvue'
): Omit<
UniApp.UniServiceJSBridge,
| 'invokeOnCallback'
......@@ -10,7 +9,6 @@ export function initBridge(
| 'invokeViewMethodKeepAlive'
| 'publishHandler'
> {
// TODO vue3 compatibility builds
const emitter = new E()
return {
on(event: string, callback: UniApp.CallbackFunction) {
......
......@@ -3,3 +3,4 @@ export * from './view'
export * from './service'
export * from './helpers'
export * from './constants'
export { initBridge } from './helpers/bridge'
......@@ -992,7 +992,7 @@ packages:
'@babel/helper-compilation-targets': 7.16.7
'@babel/helper-module-imports': 7.16.7
'@babel/helper-plugin-utils': 7.16.7
'@babel/traverse': 7.16.5
'@babel/traverse': 7.17.0
debug: 4.3.3
lodash.debounce: 4.0.8
resolve: 1.20.0
......@@ -1009,7 +1009,7 @@ packages:
'@babel/helper-compilation-targets': 7.16.7
'@babel/helper-module-imports': 7.16.7
'@babel/helper-plugin-utils': 7.16.7
'@babel/traverse': 7.16.5
'@babel/traverse': 7.17.0
debug: 4.3.3
lodash.debounce: 4.0.8
resolve: 1.20.0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册