Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 20486c7

Browse files
committed
feat: skip v-model case + skip directives case
1 parent 959fe71 commit 20486c7

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

packages/vue-vapor/__tests__/e2e/todomvc.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ describe('e2e: todomvc', () => {
167167
expect(await count('.todo:not(.completed)')).toBe(3)
168168
}
169169

170-
test.fails(
170+
test(
171171
'composition',
172172
async () => {
173173
await testTodomvc('composition')

packages/vue-vapor/examples/composition/todomvc.html

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div id="app"></div>
55

66
<script>
7-
const { createVaporApp, defineComponent, reactive, computed, watchEffect, onMounted, onUnmounted } = VueVapor
7+
const { createVaporApp, defineComponent, reactive, computed, watchEffect, onMounted, onUnmounted, nextTick } = VueVapor
88

99
const STORAGE_KEY = 'todos-vuejs-3.x'
1010
const todoStorage = {
@@ -110,9 +110,11 @@
110110
state.todos.splice(state.todos.indexOf(todo), 1)
111111
}
112112

113-
function editTodo(todo) {
113+
async function editTodo(todo) {
114114
state.beforeEditCache = todo.title
115115
state.editedTodo = todo
116+
await nextTick()
117+
document.getElementById(`todo-${todo.id}-input`).focus()
116118
}
117119

118120
function doneEdit(todo) {
@@ -147,7 +149,7 @@
147149
},
148150
})
149151

150-
const { resolveDirective: _resolveDirective, children: _children, vModelText: _vModelText, withDirectives: _withDirectives, vShow: _vShow, vModelCheckbox: _vModelCheckbox, next: _next, delegate: _delegate, on: _on, setText: _setText, setClass: _setClass, renderEffect: _renderEffect, createFor: _createFor, insert: _insert, setDynamicProp: _setDynamicProp, delegateEvents: _delegateEvents, template: _template } = VueVapor
152+
const { children: _children, vModelText: _vModelText, withDirectives: _withDirectives, vShow: _vShow, next: _next, delegate: _delegate, on: _on, setDynamicProp: _setDynamicProp, setText: _setText, setClass: _setClass, renderEffect: _renderEffect, createFor: _createFor, insert: _insert, delegateEvents: _delegateEvents, template: _template } = VueVapor
151153
const t0 = _template("<li><div class=\"view\"><input class=\"toggle\" type=\"checkbox\"><label></label><button class=\"destroy\"></button></div><input class=\"edit\" type=\"text\"></li>")
152154
const t1 = _template("<section class=\"todoapp\"><header class=\"header\"><h1>todos</h1><input class=\"new-todo\" autofocus autocomplete=\"off\" placeholder=\"What needs to be done?\"></header><section class=\"main\"><input id=\"toggle-all\" class=\"toggle-all\" type=\"checkbox\"><label for=\"toggle-all\">Mark all as complete</label><ul class=\"todo-list\"></ul></section><footer class=\"footer\"><span class=\"todo-count\"><strong></strong><span></span></span><ul class=\"filters\"><li><a href=\"#/all\">All</a></li><li><a href=\"#/active\">Active</a></li><li><a href=\"#/completed\">Completed</a></li></ul><button class=\"clear-completed\"> Clear completed </button></footer></section>")
153155
_delegateEvents("keyup", "dblclick", "click")
@@ -159,7 +161,6 @@
159161
const n10 = _children(n18, 1)
160162
_withDirectives(n10, [[_vShow, () => _ctx.state.todos.length]])
161163
const n1 = n10.firstChild
162-
_withDirectives(n1, [[_vModelCheckbox, () => _ctx.state.allDone]])
163164
const n9 = _next(n1, 2)
164165
const n17 = n10.nextSibling
165166
_withDirectives(n17, [[_vShow, () => _ctx.state.todos.length]])
@@ -174,20 +175,17 @@
174175
_delegate(n0, "keyup", () => _ctx.addTodo, {
175176
keys: ["enter"]
176177
})
177-
_delegate(n1, "update:modelValue", () => $event => (_ctx.state.allDone = $event))
178178
_on(n1, "change", () => $event => (_ctx.state.allDone = $event.target.checked))
179179
const n2 = _createFor(() => (_ctx.state.filteredTodos), (_block) => {
180180
const n8 = t0()
181181
const n4 = _children(n8, 0, 0)
182-
_withDirectives(n4, [[_vModelCheckbox, () => _block.s[0].completed]])
183182
const n5 = n4.nextSibling
184183
const n6 = n5.nextSibling
185184
const n7 = _children(n8, 1)
186-
_withDirectives(n7, [[_vModelText, () => _block.s[0].title], [_ctx.vTodoFocus, () => _block.s[0] === _ctx.state.editedTodo]])
187-
_delegate(n4, "update:modelValue", () => $event => (_block.s[0].completed = $event))
185+
_on(n4, "change", () => $event => (_block.s[0].completed = $event.target.checked))
188186
_delegate(n5, "dblclick", () => $event => (_ctx.editTodo(_block.s[0])))
189187
_delegate(n6, "click", () => $event => (_ctx.removeTodo(_block.s[0])))
190-
_delegate(n7, "update:modelValue", () => $event => (_block.s[0].title = $event))
188+
_on(n7, "input", () => $event => (_block.s[0].title = $event.target.value))
191189
_on(n7, "blur", () => $event => (_ctx.doneEdit(_block.s[0])))
192190
_delegate(n7, "keyup", () => $event => (_ctx.doneEdit(_block.s[0])), {
193191
keys: ["enter"]
@@ -197,11 +195,14 @@
197195
})
198196
const _updateEffect = () => {
199197
const [todo] = _block.s
198+
_setDynamicProp(n4, "checked", todo.completed)
200199
_setText(n5, todo.title)
200+
_setDynamicProp(n7, "value", todo.title)
201+
_setDynamicProp(n7, "id", `todo-${todo.id}-input`)
201202
_setClass(n8, ["todo", {
202-
completed: todo.completed,
203-
editing: todo === _ctx.state.editedTodo,
204-
}])
203+
completed: todo.completed,
204+
editing: todo === _ctx.state.editedTodo,
205+
}])
205206
}
206207
_renderEffect(_updateEffect)
207208
return [n8, _updateEffect]

playground/src/example-todomvc.vue

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
watchEffect,
77
onMounted,
88
onUnmounted,
9+
nextTick,
910
} from 'vue/vapor'
1011
1112
import 'todomvc-app-css/index.css'
@@ -114,9 +115,11 @@ export default defineComponent({
114115
state.todos.splice(state.todos.indexOf(todo), 1)
115116
}
116117
117-
function editTodo(todo) {
118+
async function editTodo(todo) {
118119
state.beforeEditCache = todo.title
119120
state.editedTodo = todo
121+
await nextTick()
122+
document.getElementById(`todo-${todo.id}-input`).focus()
120123
}
121124
122125
function doneEdit(todo) {
@@ -149,14 +152,6 @@ export default defineComponent({
149152
removeCompleted,
150153
}
151154
},
152-
153-
directives: {
154-
'todo-focus': (el, { value }) => {
155-
if (value) {
156-
el.focus()
157-
}
158-
},
159-
},
160155
})
161156
</script>
162157

@@ -178,7 +173,6 @@ export default defineComponent({
178173
id="toggle-all"
179174
class="toggle-all"
180175
type="checkbox"
181-
v-model="state.allDone"
182176
:checked="state.allDone"
183177
@change="state.allDone = $event.target.checked"
184178
/>
@@ -194,15 +188,21 @@ export default defineComponent({
194188
}"
195189
>
196190
<div class="view">
197-
<input class="toggle" type="checkbox" v-model="todo.completed" />
191+
<input
192+
class="toggle"
193+
type="checkbox"
194+
:checked="todo.completed"
195+
@change="todo.completed = $event.target.checked"
196+
/>
198197
<label @dblclick="editTodo(todo)">{{ todo.title }}</label>
199198
<button class="destroy" @click="removeTodo(todo)"></button>
200199
</div>
201200
<input
201+
:id="`todo-${todo.id}-input`"
202202
class="edit"
203203
type="text"
204-
v-model="todo.title"
205-
v-todo-focus="todo === state.editedTodo"
204+
:value="todo.title"
205+
@input="todo.title = $event.target.value"
206206
@blur="doneEdit(todo)"
207207
@keyup.enter="doneEdit(todo)"
208208
@keyup.escape="cancelEdit(todo)"

0 commit comments

Comments
 (0)