Skip to content

Commit

Permalink
Merge pull request #1241 from AdamCaoQAQ/feat_hummer_mode
Browse files Browse the repository at this point in the history
feat: hummer mode setup support
  • Loading branch information
Blackgan3 authored Jul 11, 2023
2 parents 8f3578d + 81ccbf5 commit c3f2575
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
52 changes: 52 additions & 0 deletions packages/core/src/platform/export/index.tenon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
effectScope as vueEffectScope,
getCurrentScope as getCurrentVueScope,
onScopeDispose
} from 'vue'

export {
// watch
watchEffect,
watchSyncEffect,
watchPostEffect,
watch,
// reactive
reactive,
isReactive,
shallowReactive,
set,
del,
markRaw,
// ref
ref,
unref,
toRef,
toRefs,
isRef,
customRef,
shallowRef,
triggerRef,
// computed
computed,
// instance
getCurrentInstance
} from 'vue'

const noop = () => {
}

const fixEffectScope = (scope) => {
scope.pause = noop
scope.resume = noop
}

const effectScope = (detached) => fixEffectScope(vueEffectScope(detached))
const getCurrentScope = () => fixEffectScope(getCurrentVueScope())

export {
// effectScope
effectScope,
getCurrentScope,
onScopeDispose
}

25 changes: 24 additions & 1 deletion packages/core/src/platform/patch/tenon/getDefaultOptions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import builtInKeysMap from '../builtInKeysMap'
import mergeOptions from '../../../core/mergeOptions'
import MPXProxy from '../../../core/proxy'
import { getCurrentInstance as getCurrentVueInstance } from '../../export/index'
import MpxProxy, { setCurrentInstance, unsetCurrentInstance } from '../../../core/proxy'
import { diffAndCloneA } from '@mpxjs/utils'
import { UPDATED, CREATED, MOUNTED, UNMOUNTED } from '../../../core/innerLifecycle'

Expand Down Expand Up @@ -33,6 +34,28 @@ function initProxy (context, rawOptions) {
}

export function getDefaultOptions (type, { rawOptions = {}, currentInject }) {

const rawSetup = rawOptions.setup
if (rawSetup) {
rawOptions.setup = (props) => {
const instance = getCurrentVueInstance().proxy
initProxy(instance, rawOptions)
setCurrentInstance(instance.__mpxProxy)
const newContext = {
triggerEvent: instance.triggerEvent.bind(instance),
refs: instance.$refs,
forceUpdate: instance.$forceUpdate.bind(instance),
selectComponent: instance.selectComponent.bind(instance),
selectAllComponents: instance.selectAllComponents.bind(instance),
createSelectorQuery: instance.createSelectorQuery.bind(instance),
createIntersectionObserver: instance.createIntersectionObserver.bind(instance)
}
const setupRes = rawSetup(props, newContext)
unsetCurrentInstance(instance.__mpxProxy)
return setupRes
}
}

const hookNames = type === 'page' ? ['onLoad', 'onReady', 'onUnload'] : ['created', 'mounted', 'unmounted']
const rootMixins = [{
[hookNames[0]] (...params) {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@better-scroll/wheel": "^2.2.1",
"@better-scroll/zoom": "^2.2.1",
"@hummer/tenon-dev-server-webpack-plugin": "0.0.2",
"@hummer/tenon-loader": "^1.1.0",
"@hummer/tenon-loader": "^1.2.0",
"@hummer/tenon-style-loader": "^0.2.0",
"acorn-walk": "^7.2.0",
"async": "^2.6.0",
Expand Down

0 comments on commit c3f2575

Please sign in to comment.