Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk authored and sxzz committed Sep 27, 2024
1 parent 3c2590e commit ebb3ae7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 23 deletions.
18 changes: 9 additions & 9 deletions packages/runtime-vapor/src/apiCreateFor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
type EffectScope,
type Signal,
type ShallowRef,
effectScope,
signal,
} from '@johnsoncodehk/signals'
shallowRef,
} from '/Users/johnsonchu/Desktop/GitHub/refs/vue'
import { isArray, isObject, isString } from '@vue/shared'
import {
createComment,
Expand All @@ -22,9 +22,9 @@ import { withMemo } from './memo'
interface ForBlock extends Fragment {
scope: EffectScope
state: [
item: Signal<any>,
key: Signal<any>,
index: Signal<number | undefined>,
item: ShallowRef<any>,
key: ShallowRef<any>,
index: ShallowRef<number | undefined>,
]
key: any
memo: any[] | undefined
Expand Down Expand Up @@ -251,9 +251,9 @@ export const createFor = (

const [item, key, index] = getItem(source, idx)
const state = [
signal(item),
signal(key),
signal(index),
shallowRef(item),
shallowRef(key),
shallowRef(index),
] as ForBlock['state']
const block: ForBlock = (newBlocks[idx] = {
nodes: null!, // set later
Expand Down
5 changes: 4 additions & 1 deletion packages/runtime-vapor/src/apiCreateIf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { renderEffect } from './renderEffect'
import { type Block, type Fragment, fragmentKey } from './apiRender'
import { type EffectScope, effectScope } from '@johnsoncodehk/signals'
import {
type EffectScope,
effectScope,
} from '/Users/johnsonchu/Desktop/GitHub/refs/vue'
import { createComment, createTextNode, insert, remove } from './dom/element'

type BlockFn = () => Block
Expand Down
9 changes: 6 additions & 3 deletions packages/runtime-vapor/src/apiCreateSelector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { type Signal, signal } from '@johnsoncodehk/signals'
import {
type ShallowRef,
shallowRef,
} from '/Users/johnsonchu/Desktop/GitHub/refs/vue'
import { watchEffect } from './apiWatch'

export function createSelector<T, U extends T>(
Expand Down Expand Up @@ -26,8 +29,8 @@ export function createSelector<T, U extends T>(
})

return key => {
let l: Signal<boolean | undefined> & { _count?: number }
if (!(l = subs.get(key))) subs.set(key, (l = signal()))
let l: ShallowRef<boolean | undefined> & { _count?: number }
if (!(l = subs.get(key))) subs.set(key, (l = shallowRef()))
l.value
l._count ? l._count++ : (l._count = 1)
// onScopeDispose(() => (l._count! > 1 ? l._count!-- : subs.delete(key)))
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-vapor/src/apiLifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
// type DebuggerEvent,
pauseTracking,
resetTracking,
} from '@johnsoncodehk/signals'
} from '/Users/johnsonchu/Desktop/GitHub/refs/vue'
import { ErrorTypeStrings, callWithAsyncErrorHandling } from './errorHandling'
import { toHandlerKey } from '@vue/shared'
import { VaporLifecycleHooks } from './enums'
Expand Down
5 changes: 4 additions & 1 deletion packages/runtime-vapor/src/apiRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { insert, querySelector, remove } from './dom/element'
import { flushPostFlushCbs, queuePostFlushCb } from './scheduler'
import { invokeLifecycle } from './componentLifecycle'
import { VaporLifecycleHooks } from './enums'
import { pauseTracking, resetTracking } from '@johnsoncodehk/signals'
import {
pauseTracking,
resetTracking,
} from '/Users/johnsonchu/Desktop/GitHub/refs/vue'
import { isArray, isFunction, isObject } from '@vue/shared'
import { fallThroughAttrs } from './componentAttrs'
import { VaporErrorCodes, callWithErrorHandling } from './errorHandling'
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-vapor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ export const setDevtoolsHook = (
__DEV__ || __ESM_BUNDLER__ ? _setDevtoolsHook : NOOP
) as typeof _setDevtoolsHook

export * from '@johnsoncodehk/signals'
export * from '/Users/johnsonchu/Desktop/GitHub/refs/vue'
17 changes: 10 additions & 7 deletions packages/runtime-vapor/src/renderEffect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { EffectFlags, ReactiveEffect, getCurrentScope } from '@vue/reactivity'
import { invokeArrayFns } from '@vue/shared'
import {
type ComponentInternalInstance,
Expand All @@ -13,16 +12,20 @@ import {
} from './scheduler'
import { VaporErrorCodes, callWithAsyncErrorHandling } from './errorHandling'
import { memoStack } from './memo'
import { effect as effect2 } from '@johnsoncodehk/signals'
import {
ReactiveEffect,
effect as effect2,
getCurrentScope,
} from '/Users/johnsonchu/Desktop/GitHub/refs/vue'

export function renderEffect(cb: () => void): void {
const instance = getCurrentInstance()
// const scope = getCurrentScope()
const scope = getCurrentScope()

// if (scope) {
// const baseCb = cb
// cb = () => scope.run(baseCb)
// }
if (scope) {
const baseCb = cb
cb = () => scope.run(baseCb)
}

if (instance) {
const baseCb = cb
Expand Down

0 comments on commit ebb3ae7

Please sign in to comment.