Skip to content

Commit 7a5fa99

Browse files
Merge branch 'release/v0.17.3'
2 parents db5a898 + 2403cf7 commit 7a5fa99

File tree

9 files changed

+142
-100
lines changed

9 files changed

+142
-100
lines changed

config/rollup.base.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export default {
3636
esbuild({
3737
target: 'es2015',
3838
sourceMap: true,
39-
minify: isProduction
39+
minify: isProduction,
40+
define: {
41+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
42+
}
4043
})
4144
]
4245
}

package-lock.json

Lines changed: 39 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ef-core",
3-
"version": "0.17.2",
3+
"version": "0.17.3",
44
"description": "Core of ef.js (without parser)",
55
"main": "dist/ef-core.min.js",
66
"module": "src/ef-core.js",
@@ -34,7 +34,7 @@
3434
"chalk": "^5.3.0",
3535
"chokidar": "^3.5.3",
3636
"cross-env": "^7.0.3",
37-
"eslint": "^8.43.0",
37+
"eslint": "^8.44.0",
3838
"jsdoc": "^4.0.2",
3939
"rollup": "^3.26.0",
4040
"rollup-plugin-browsersync": "^1.3.3",

src/ef-core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const create = (ast, name) => {
107107
return EFComponent
108108
}
109109

110-
let coreVersion = '0.17.2'
110+
let coreVersion = '0.17.3'
111111

112112
if (process.env.NODE_ENV !== 'production') {
113113
coreVersion = `${coreVersion}+debug`

src/lib/creator.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const checkDestroyed = (state) => {
2222
if (!state.$ctx) throw new Error('[EF] This component has been destroyed!')
2323
}
2424

25-
const bindTextNode = (ctx, {apply, node}) => {
25+
const bindTextNode = (ctx, node, apply) => {
2626
// Data binding text node
2727
const textNode = DOM.document.createTextNode('')
2828
const { dataNode, handlerNode, _key } = initBinding(ctx, {bind: node})
@@ -40,7 +40,7 @@ const bindTextNode = (ctx, {apply, node}) => {
4040
apply(textNode)
4141
}
4242

43-
const updateMountNode = ({ctx, key, value}) => {
43+
const updateMountNode = (ctx, key, value) => {
4444
const {children} = ctx
4545
const child = children[key]
4646
const {anchor, node} = child
@@ -56,27 +56,27 @@ const updateMountNode = ({ctx, key, value}) => {
5656
}
5757
// Update stored value
5858
child.node = value
59-
if (value) value.$mount({target: anchor, parent: ctx.state, option: mountOptions.BEFORE, key})
59+
if (value) value.$mount({target: anchor, parent: ctx.state, option: mountOptions.AFTER, key})
6060
exec()
6161
}
6262

63-
const updateMountList = ({ctx, key, value}) => {
63+
const updateMountList = (ctx, key, value) => {
6464
const {children} = ctx
6565
const {anchor, node} = children[key]
6666
if (ARR.equals(node, value)) return
6767
inform()
6868
if (node.length) node.clear()
6969
if (value) {
7070
value = ARR.copy(value)
71-
useFragment((fragment, putBack) => {
71+
useFragment((fragment, recycleFragment) => {
7272
// Update components
7373
for (let item of value) DOM.append(fragment, shared.toEFComponent(item).$mount({parent: ctx.state, key}))
7474
// Update stored value
7575
ARR.push(node, ...value)
7676
// Append to current component
7777
queueDom(() => {
7878
DOM.after(anchor, fragment)
79-
putBack()
79+
recycleFragment()
8080
})
8181
})
8282
}
@@ -89,6 +89,7 @@ const mountPointUpdaters = [
8989
]
9090

9191
const applyMountPoint = (type, key, tpl) => {
92+
const updater = mountPointUpdaters[type]
9293
Object.defineProperty(tpl.prototype, key, {
9394
get() {
9495
if (process.env.NODE_ENV !== 'production') checkDestroyed(this)
@@ -97,24 +98,26 @@ const applyMountPoint = (type, key, tpl) => {
9798
set(value) {
9899
if (process.env.NODE_ENV !== 'production') checkDestroyed(this)
99100
const ctx = this.$ctx
100-
mountPointUpdaters[type]({ctx, key, value})
101+
updater(ctx, key, value)
101102
},
102103
enumerable: true
103104
})
104105
}
105106

106-
const bindMountNode = ({ctx, key, anchor}) => {
107+
const bindMountNode = (ctx, key, anchor) => {
107108
const { children } = ctx
108109
const info = {anchor}
109110
children[key] = info
110111
anchor[EFMountPoint] = info
111112
}
112113

113-
const bindMountList = ({ctx, key, anchor}) => {
114+
// eslint-disable-next-line max-params
115+
const bindMountList = (ctx, key, anchor, aftAnchor) => {
114116
const { children } = ctx
115117
children[key] = {
116-
node: defineArr([], {ctx, key, anchor}),
117-
anchor
118+
node: defineArr([], {ctx, key, anchor, aftAnchor}),
119+
anchor,
120+
aftAnchor
118121
}
119122
anchor[EFMountPoint] = children[key]
120123
}
@@ -137,19 +140,23 @@ const resolveAST = (ctx, {apply, node, nodeType, namespace, create}) => {
137140
// Recursive call for child element
138141
if (typeOf(node[0]) === 'object') apply(create(ctx, {node, namespace}))
139142
// Dynamic text node
140-
else bindTextNode(ctx, {apply, node})
143+
else bindTextNode(ctx, node, apply)
141144
break
142145
}
143146
// Mount points
144147
case 'object': {
148+
if (process.env.NODE_ENV !== 'production') apply(DOM.document.createComment(`<MountPoint${node.t && ' type="list" ' || ' '}name="${node.n}">`))
145149
const anchor = DOM.document.createTextNode('')
146-
// Single node mount point
147-
if (node.t === 0) bindMountNode({ctx, key: node.n, anchor})
148-
// Multi node mount point
149-
else bindMountList({ctx, key: node.n, anchor})
150150
// Append anchor
151-
if (process.env.NODE_ENV !== 'production') apply(DOM.document.createComment(`<MountPoint${node.t && ' type="list" ' || ' '}name="${node.n}">`))
152151
apply(anchor)
152+
// Single node mount point
153+
if (node.t === 0) bindMountNode(ctx, node.n, anchor)
154+
else {
155+
// Multi node mount point
156+
const aftAnchor = DOM.document.createTextNode('')
157+
apply(aftAnchor)
158+
bindMountList(ctx, node.n, anchor, aftAnchor)
159+
}
153160
if (process.env.NODE_ENV !== 'production') apply(DOM.document.createComment('</MountPoint>'))
154161
break
155162
}
@@ -211,7 +218,7 @@ const create = (ctx, {node, namespace}) => {
211218
if (namespace === htmlNS) namespace = ''
212219

213220
// First create an element according to the description
214-
const [element, type] = createElement(ctx, {info, namespace, fragment, custom})
221+
const [element, type] = createElement(ctx, info, namespace, fragment, custom)
215222

216223
let apply = noop
217224

0 commit comments

Comments
 (0)