Skip to content

Commit 58cbf77

Browse files
committed
more size tweaks
1 parent d3b72da commit 58cbf77

File tree

8 files changed

+29
-22
lines changed

8 files changed

+29
-22
lines changed

src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Directive } from './directives'
44
import { createContext } from './walk'
55
import { toDisplayString } from './directives/text'
66

7-
export function createApp(initialData?: any) {
7+
export const createApp = (initialData?: any) => {
88
// root context
99
const ctx = createContext()
1010
if (initialData) {

src/directives/bind.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ export const bind: Directive<Element & { _class?: string }> = ({
4545
})
4646
}
4747

48-
function setProp(
48+
const setProp = (
4949
el: Element & { _class?: string },
5050
key: string,
5151
value: any,
5252
prevValue?: any
53-
) {
53+
) => {
5454
if (key === 'class') {
5555
el.setAttribute(
5656
'class',
@@ -101,11 +101,11 @@ function setProp(
101101

102102
const importantRE = /\s*!important$/
103103

104-
function setStyle(
104+
const setStyle = (
105105
style: CSSStyleDeclaration,
106106
name: string,
107107
val: string | string[]
108-
) {
108+
) => {
109109
if (isArray(val)) {
110110
val.forEach((v) => setStyle(style, name, v))
111111
} else {

src/directives/for.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { isArray, isObject } from '@vue/shared'
22
import { Block } from '../block'
33
import { evaluate } from '../eval'
44
import { Context } from '../walk'
5-
import { createScopedContext } from './data'
5+
import { createScopedContext } from './scope'
66

77
const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/
88
const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
@@ -58,15 +58,17 @@ export const _for = (el: Element, exp: string, ctx: Context) => {
5858
let scopes: ChildScope[]
5959
let keyToIndexMap: Map<any, number>
6060

61-
function createChildScopes(source: unknown): [ChildScope[], KeyToIndexMap] {
61+
const createChildScopes = (
62+
source: unknown
63+
): [ChildScope[], KeyToIndexMap] => {
6264
const map: KeyToIndexMap = new Map()
6365
const scopes: ChildScope[] = []
6466

65-
function createScope(
67+
const createScope = (
6668
value: any,
6769
index: number,
6870
objKey?: string
69-
): ChildScope {
71+
): ChildScope => {
7072
// TODO destructure
7173
const data = { [valueExp]: value }
7274
if (objKey) {
@@ -102,7 +104,7 @@ export const _for = (el: Element, exp: string, ctx: Context) => {
102104
return [scopes, map]
103105
}
104106

105-
function mountBlock({ ctx, key }: ChildScope, ref: Node) {
107+
const mountBlock = ({ ctx, key }: ChildScope, ref: Node) => {
106108
const block = new Block(el, ctx)
107109
block.key = key
108110
block.insert(parent, ref)

src/directives/if.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const _if = (el: Element, exp: string, ctx: Context) => {
4545

4646
let block: Block | undefined
4747

48-
function removeActiveBlock() {
48+
const removeActiveBlock = () => {
4949
if (block) {
5050
parent.insertBefore(anchor, block.el)
5151
block.remove()

src/directives/data.ts renamed to src/directives/scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { reactive } from '@vue/reactivity'
22
import { isObject } from '@vue/shared'
33
import { Context } from '../walk'
44

5-
export function createScopedContext(ctx: Context, data: object): Context {
5+
export const createScopedContext = (ctx: Context, data: object): Context => {
66
if (isObject(data)) {
77
const parentScope = ctx.scope
88
const mergedScope = Object.assign(Object.create(parentScope), data)

src/eval.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const evalCache: Record<string, Function> = Object.create(null)
22

3-
export function evaluate(scope: any, exp: string, el?: Node) {
3+
export const evaluate = (scope: any, exp: string, el?: Node) => {
44
const fn = evalCache[exp] || (evalCache[exp] = toFunction(exp))
55
try {
66
return fn(scope, el)
@@ -9,7 +9,7 @@ export function evaluate(scope: any, exp: string, el?: Node) {
99
}
1010
}
1111

12-
function toFunction(exp: string): Function {
12+
const toFunction = (exp: string): Function => {
1313
try {
1414
return new Function(`$data`, `$el`, `with ($data) { return (${exp}) }`)
1515
} catch (e) {

src/scheduler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ let queued = false
22
const queue: Function[] = []
33
const p = Promise.resolve()
44

5-
export function queueJob(job: Function) {
5+
export const queueJob = (job: Function) => {
66
if (!queue.includes(job)) queue.push(job)
77
if (!queued) {
88
queued = true
99
p.then(flushJobs)
1010
}
1111
}
1212

13-
export function flushJobs() {
13+
const flushJobs = () => {
1414
for (let i = 0; i < queue.length; i++) {
1515
queue[i]()
1616
}

src/walk.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { builtInDirectives, Directive } from './directives'
22
import { _if } from './directives/if'
33
import { _for } from './directives/for'
44
import { bind } from './directives/bind'
5-
import { createScopedContext } from './directives/data'
5+
import { createScopedContext } from './directives/scope'
66
import { on } from './directives/on'
77
import { text } from './directives/text'
88
import { evaluate } from './eval'
@@ -20,7 +20,7 @@ export interface Context {
2020
cleanups: (() => void)[]
2121
}
2222

23-
export function createContext(parent?: Context): Context {
23+
export const createContext = (parent?: Context): Context => {
2424
const ctx: Context = {
2525
...parent,
2626
scope: parent ? parent.scope : reactive({}),
@@ -43,7 +43,7 @@ const dirRE = /^(?:v-|:|@)/
4343
const modifierRE = /\.([\w-]+)/g
4444
const interpolationRE = /\{\{([^]+?)\}\}/g
4545

46-
export function walk(node: Node, ctx: Context): ChildNode | null | void {
46+
export const walk = (node: Node, ctx: Context): ChildNode | null | void => {
4747
const type = node.nodeType
4848
if (type === 1) {
4949
// Element
@@ -114,7 +114,12 @@ export function walk(node: Node, ctx: Context): ChildNode | null | void {
114114
}
115115
}
116116

117-
function processDirective(el: Element, raw: string, exp: string, ctx: Context) {
117+
const processDirective = (
118+
el: Element,
119+
raw: string,
120+
exp: string,
121+
ctx: Context
122+
) => {
118123
let dir: Directive
119124
let arg: string | undefined
120125
let modifiers: Record<string, true> | undefined
@@ -146,14 +151,14 @@ function processDirective(el: Element, raw: string, exp: string, ctx: Context) {
146151
}
147152
}
148153

149-
function applyDirective(
154+
const applyDirective = (
150155
el: Node,
151156
dir: Directive<any>,
152157
exp: string,
153158
ctx: Context,
154159
arg?: string,
155160
modifiers?: Record<string, true>
156-
) {
161+
) => {
157162
const get = (e = exp) => evaluate(ctx.scope, e, el)
158163
const cleanup = dir({ el, get, effect: ctx.effect, ctx, exp, arg, modifiers })
159164
if (cleanup) {

0 commit comments

Comments
 (0)