Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sven Franck
todomvc
Commits
f183e30a
Commit
f183e30a
authored
Aug 26, 2015
by
Arthur Verschaeve
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1423 from marcolamberto/mithril-input-refresh-fix
Changing redraw strategy while handling input events
parents
e97e13c5
80f9fbe4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
6 deletions
+17
-6
examples/mithril/js/controllers/todo.js
examples/mithril/js/controllers/todo.js
+5
-1
examples/mithril/js/views/main-view.js
examples/mithril/js/views/main-view.js
+12
-5
No files found.
examples/mithril/js/controllers/todo.js
View file @
f183e30a
...
...
@@ -8,7 +8,7 @@ app.controller = function () {
this
.
list
=
app
.
storage
.
get
();
// Update with props
this
.
list
=
this
.
list
.
map
(
function
(
item
)
{
this
.
list
=
this
.
list
.
map
(
function
(
item
)
{
return
new
app
.
Todo
(
item
);
});
...
...
@@ -53,6 +53,10 @@ app.controller = function () {
};
this
.
doneEditing
=
function
(
todo
,
index
)
{
if
(
!
todo
.
editing
())
{
return
;
}
todo
.
editing
(
false
);
todo
.
title
(
todo
.
title
().
trim
());
if
(
!
todo
.
title
())
{
...
...
examples/mithril/js/views/main-view.js
View file @
f183e30a
...
...
@@ -5,15 +5,18 @@ var app = app || {};
// View utility
app
.
watchInput
=
function
(
onenter
,
onescape
)
{
return
function
(
e
)
{
m
.
redraw
.
strategy
(
'
none
'
);
if
(
e
.
keyCode
===
app
.
ENTER_KEY
)
{
onenter
();
m
.
redraw
.
strategy
(
'
diff
'
);
}
else
if
(
e
.
keyCode
===
app
.
ESC_KEY
)
{
onescape
();
m
.
redraw
.
strategy
(
'
diff
'
);
}
};
};
app
.
view
=
(
function
()
{
app
.
view
=
(
function
()
{
var
focused
=
false
;
return
function
(
ctrl
)
{
...
...
@@ -63,13 +66,17 @@ app.view = (function() {
})
]),
m
(
'
input.edit
'
,
{
value
:
task
.
title
(),
onkeyup
:
app
.
watchInput
(
ctrl
.
doneEditing
.
bind
(
ctrl
,
task
,
index
),
ctrl
.
cancelEditing
.
bind
(
ctrl
,
task
)),
oninput
:
m
.
withAttr
(
'
value
'
,
task
.
title
),
onkeyup
:
app
.
watchInput
(
ctrl
.
doneEditing
.
bind
(
ctrl
,
task
,
index
),
ctrl
.
cancelEditing
.
bind
(
ctrl
,
task
)
),
oninput
:
m
.
withAttr
(
'
value
'
,
function
(
value
)
{
m
.
redraw
.
strategy
(
'
none
'
);
task
.
title
(
value
);
}),
config
:
function
(
element
)
{
if
(
task
.
editing
())
{
element
.
focus
();
element
.
selectionStart
=
element
.
value
.
length
;
}
},
onblur
:
ctrl
.
doneEditing
.
bind
(
ctrl
,
task
,
index
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment