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
d494efd3
Commit
d494efd3
authored
Sep 13, 2017
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jshint gadgets
parent
41fbc7c5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
130 deletions
+140
-130
examples/renderjs/gadget_global.js
examples/renderjs/gadget_global.js
+79
-78
examples/renderjs/gadget_model.js
examples/renderjs/gadget_model.js
+49
-40
examples/renderjs/gadget_router.js
examples/renderjs/gadget_router.js
+12
-12
No files found.
examples/renderjs/gadget_global.js
View file @
d494efd3
/*global window, RSVP, FileReader */
/*global window, RSVP, FileReader */
/*jslint indent: 2, maxerr: 3, unparam: true */
/*jslint indent: 2, maxerr: 3, unparam: true */
(
function
(
window
,
RSVP
,
FileReader
)
{
(
function
(
window
,
RSVP
,
FileReader
)
{
"
use strict
"
;
"
use strict
"
;
window
.
loopEventListener
=
function
(
target
,
type
,
useCapture
,
callback
,
window
.
loopEventListener
=
function
(
target
,
type
,
useCapture
,
callback
,
allowDefault
)
{
allowDefault
)
{
//////////////////////////
//////////////////////////
// Infinite event listener (promise is never resolved)
// Infinite event listener (promise is never resolved)
...
@@ -25,19 +25,20 @@
...
@@ -25,19 +25,20 @@
}
}
cancelResolver
();
cancelResolver
();
}
}
function
itsANonResolvableTrap
(
resolve
,
reject
)
{
function
itsANonResolvableTrap
(
resolve
,
reject
)
{
handle_event_callback
=
function
(
evt
)
{
handle_event_callback
=
function
(
evt
)
{
evt
.
stopPropagation
();
evt
.
stopPropagation
();
if
(
allowDefault
!==
true
)
{
if
(
allowDefault
!==
true
)
{
evt
.
preventDefault
();
evt
.
preventDefault
();
}
}
cancelResolver
();
cancelResolver
();
callback_promise
=
new
RSVP
.
Queue
()
callback_promise
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
callback
(
evt
);
return
callback
(
evt
);
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
if
(
!
(
error
instanceof
RSVP
.
CancellationError
))
{
if
(
!
(
error
instanceof
RSVP
.
CancellationError
))
{
canceller
();
canceller
();
reject
(
error
);
reject
(
error
);
...
@@ -50,7 +51,7 @@
...
@@ -50,7 +51,7 @@
return
new
RSVP
.
Promise
(
itsANonResolvableTrap
,
canceller
);
return
new
RSVP
.
Promise
(
itsANonResolvableTrap
,
canceller
);
};
};
window
.
promiseEventListener
=
function
(
target
,
type
,
useCapture
)
{
window
.
promiseEventListener
=
function
(
target
,
type
,
useCapture
)
{
//////////////////////////
//////////////////////////
// Resolve the promise as soon as the event is triggered
// Resolve the promise as soon as the event is triggered
// eventListener is removed when promise is cancelled/resolved/rejected
// eventListener is removed when promise is cancelled/resolved/rejected
...
@@ -62,7 +63,7 @@
...
@@ -62,7 +63,7 @@
}
}
function
resolver
(
resolve
)
{
function
resolver
(
resolve
)
{
handle_event_callback
=
function
(
evt
)
{
handle_event_callback
=
function
(
evt
)
{
canceller
();
canceller
();
evt
.
stopPropagation
();
evt
.
stopPropagation
();
evt
.
preventDefault
();
evt
.
preventDefault
();
...
@@ -75,13 +76,13 @@
...
@@ -75,13 +76,13 @@
return
new
RSVP
.
Promise
(
resolver
,
canceller
);
return
new
RSVP
.
Promise
(
resolver
,
canceller
);
};
};
window
.
promiseReadAsText
=
function
(
file
)
{
window
.
promiseReadAsText
=
function
(
file
)
{
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
var
reader
=
new
FileReader
();
var
reader
=
new
FileReader
();
reader
.
onload
=
function
(
evt
)
{
reader
.
onload
=
function
(
evt
)
{
resolve
(
evt
.
target
.
result
);
resolve
(
evt
.
target
.
result
);
};
};
reader
.
onerror
=
function
(
evt
)
{
reader
.
onerror
=
function
(
evt
)
{
reject
(
evt
);
reject
(
evt
);
};
};
reader
.
readAsText
(
file
);
reader
.
readAsText
(
file
);
...
...
examples/renderjs/gadget_model.js
View file @
d494efd3
/*global
define, App, window, RSVP, rJS, jIO
*/
/*global
window, RSVP, rJS, jIO, Date
*/
/*jshint unused:false */
/*jshint unused:false */
(
function
(
window
,
RSVP
,
rJS
,
jIO
)
{
(
function
(
window
,
RSVP
,
rJS
,
jIO
,
Date
)
{
'
use strict
'
;
'
use strict
'
;
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
// Initialize the gadget as soon as it is loaded in memory,
// Initialize the gadget as soon as it is loaded in memory,
// blocking all other methods in itself and its ancestors.
// blocking all other methods in itself and its ancestors.
.
ready
(
function
()
{
.
ready
(
function
()
{
var
gadget
=
this
;
var
gadget
=
this
;
// Create a new jIO storage that supports queries,
// Create a new jIO storage that supports queries,
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
// Put a new todo into jIO storage, with an auto-generated ID.
// Put a new todo into jIO storage, with an auto-generated ID.
.
declareMethod
(
'
postTodo
'
,
function
(
title
)
{
.
declareMethod
(
'
postTodo
'
,
function
(
title
)
{
var
gadget
=
this
;
var
gadget
=
this
;
var
storage
=
gadget
.
state
.
storage
;
var
storage
=
gadget
.
state
.
storage
;
return
storage
.
post
({
return
storage
.
post
({
...
@@ -43,13 +43,13 @@
...
@@ -43,13 +43,13 @@
})
})
// Update the properties of an existing todo in jIO storage.
// Update the properties of an existing todo in jIO storage.
.
declareMethod
(
'
putTodo
'
,
function
(
id
,
todo
)
{
.
declareMethod
(
'
putTodo
'
,
function
(
id
,
todo
)
{
var
gadget
=
this
;
var
gadget
=
this
;
var
storage
=
gadget
.
state
.
storage
;
var
storage
=
gadget
.
state
.
storage
;
// Get todo from storage first to get all its properties.
// Get todo from storage first to get all its properties.
return
storage
.
get
(
id
)
return
storage
.
get
(
id
)
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
var
key
;
var
key
;
// Only overwrite the given properties.
// Only overwrite the given properties.
...
@@ -62,17 +62,17 @@
...
@@ -62,17 +62,17 @@
},
},
// Reject callback if todo is not found in storage.
// Reject callback if todo is not found in storage.
function
()
{
function
()
{
return
todo
;
return
todo
;
})
})
.
push
(
function
(
todo
)
{
.
push
(
function
(
todo
)
{
return
storage
.
put
(
id
,
todo
);
return
storage
.
put
(
id
,
todo
);
});
});
})
})
// Return a list of all todos in storage that match the given query.
// Return a list of all todos in storage that match the given query.
.
declareMethod
(
'
getTodos
'
,
function
(
query
)
{
.
declareMethod
(
'
getTodos
'
,
function
(
query
)
{
var
gadget
=
this
;
var
gadget
=
this
;
var
storage
=
gadget
.
state
.
storage
;
var
storage
=
gadget
.
state
.
storage
;
...
@@ -80,13 +80,16 @@
...
@@ -80,13 +80,16 @@
// in chronological order, with 'title' and 'completed' properties.
// in chronological order, with 'title' and 'completed' properties.
return
storage
.
allDocs
({
return
storage
.
allDocs
({
query
:
query
,
query
:
query
,
sort_on
:
[[
'
creation_date
'
,
'
ascending
'
]],
sort_on
:
[
[
'
creation_date
'
,
'
ascending
'
]
],
select_list
:
[
'
title
'
,
'
completed
'
]
select_list
:
[
'
title
'
,
'
completed
'
]
})
})
// Add the todo IDs into the list.
// Add the todo IDs into the list.
.
push
(
function
(
result_list
)
{
.
push
(
function
(
result_list
)
{
var
todo_list
=
[],
todo
,
i
;
var
todo_list
=
[],
todo
,
i
;
for
(
i
=
0
;
i
<
result_list
.
data
.
total_rows
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
result_list
.
data
.
total_rows
;
i
+=
1
)
{
todo
=
result_list
.
data
.
rows
[
i
];
todo
=
result_list
.
data
.
rows
[
i
];
todo_list
.
push
({
todo_list
.
push
({
...
@@ -100,13 +103,15 @@
...
@@ -100,13 +103,15 @@
})
})
// Get the count of all total todos and all active todos.
// Get the count of all total todos and all active todos.
.
declareMethod
(
'
getTodoCountDict
'
,
function
()
{
.
declareMethod
(
'
getTodoCountDict
'
,
function
()
{
var
gadget
=
this
;
var
gadget
=
this
;
var
storage
=
gadget
.
state
.
storage
;
var
storage
=
gadget
.
state
.
storage
;
// Get a list of all todos in storage with the 'completed' property
// Get a list of all todos in storage with the 'completed' property
return
storage
.
allDocs
({
select_list
:
[
'
completed
'
]})
return
storage
.
allDocs
({
.
push
(
function
(
result_list
)
{
select_list
:
[
'
completed
'
]
})
.
push
(
function
(
result_list
)
{
var
todo_count_dict
=
{
var
todo_count_dict
=
{
total
:
result_list
.
data
.
total_rows
,
total
:
result_list
.
data
.
total_rows
,
active
:
0
active
:
0
...
@@ -123,25 +128,29 @@
...
@@ -123,25 +128,29 @@
})
})
// Change the title of a todo.
// Change the title of a todo.
.
declareMethod
(
'
changeTitle
'
,
function
(
id
,
title
)
{
.
declareMethod
(
'
changeTitle
'
,
function
(
id
,
title
)
{
var
gadget
=
this
;
var
gadget
=
this
;
return
gadget
.
putTodo
(
id
,
{
title
:
title
});
return
gadget
.
putTodo
(
id
,
{
title
:
title
});
})
})
// Change the completion status of a todo.
// Change the completion status of a todo.
.
declareMethod
(
'
toggleOne
'
,
function
(
id
,
completed
)
{
.
declareMethod
(
'
toggleOne
'
,
function
(
id
,
completed
)
{
var
gadget
=
this
;
var
gadget
=
this
;
return
gadget
.
putTodo
(
id
,
{
completed
:
completed
});
return
gadget
.
putTodo
(
id
,
{
completed
:
completed
});
})
})
// Change the completion status of all todos.
// Change the completion status of all todos.
.
declareMethod
(
'
toggleAll
'
,
function
(
completed
)
{
.
declareMethod
(
'
toggleAll
'
,
function
(
completed
)
{
var
gadget
=
this
;
var
gadget
=
this
;
var
storage
=
gadget
.
state
.
storage
;
var
storage
=
gadget
.
state
.
storage
;
// Get all todos, and change the completion status of each one.
// Get all todos, and change the completion status of each one.
return
storage
.
allDocs
()
return
storage
.
allDocs
()
.
push
(
function
(
result_list
)
{
.
push
(
function
(
result_list
)
{
var
promise_list
=
[];
var
promise_list
=
[];
for
(
var
i
=
0
;
i
<
result_list
.
data
.
total_rows
;
i
+=
1
)
{
for
(
var
i
=
0
;
i
<
result_list
.
data
.
total_rows
;
i
+=
1
)
{
promise_list
.
push
(
gadget
.
toggleOne
(
promise_list
.
push
(
gadget
.
toggleOne
(
...
@@ -153,19 +162,19 @@
...
@@ -153,19 +162,19 @@
})
})
// Remove one todo from the storage.
// Remove one todo from the storage.
.
declareMethod
(
'
removeOne
'
,
function
(
id
)
{
.
declareMethod
(
'
removeOne
'
,
function
(
id
)
{
var
gadget
=
this
;
var
gadget
=
this
;
var
storage
=
gadget
.
state
.
storage
;
var
storage
=
gadget
.
state
.
storage
;
return
storage
.
remove
(
id
);
return
storage
.
remove
(
id
);
})
})
// Remove all completed todos from the storage.
// Remove all completed todos from the storage.
.
declareMethod
(
'
removeCompleted
'
,
function
()
{
.
declareMethod
(
'
removeCompleted
'
,
function
()
{
var
gadget
=
this
;
var
gadget
=
this
;
// Get a list of all todos, and only remove the completed ones.
// Get a list of all todos, and only remove the completed ones.
return
gadget
.
getTodos
()
return
gadget
.
getTodos
()
.
push
(
function
(
todo_list
)
{
.
push
(
function
(
todo_list
)
{
var
promise_list
=
[];
var
promise_list
=
[];
for
(
var
i
=
0
;
i
<
todo_list
.
length
;
i
+=
1
)
{
for
(
var
i
=
0
;
i
<
todo_list
.
length
;
i
+=
1
)
{
if
(
todo_list
[
i
].
completed
)
{
if
(
todo_list
[
i
].
completed
)
{
...
@@ -176,4 +185,4 @@
...
@@ -176,4 +185,4 @@
});
});
});
});
}(
window
,
RSVP
,
rJS
,
jIO
));
}(
window
,
RSVP
,
rJS
,
jIO
,
Date
));
examples/renderjs/gadget_router.js
View file @
d494efd3
/*global
define, App,
window, RSVP, rJS, loopEventListener */
/*global window, RSVP, rJS, loopEventListener */
/*jshint unused:false */
/*jshint unused:false */
(
function
(
window
,
RSVP
,
rJS
,
loopEventListener
)
{
(
function
(
window
,
RSVP
,
rJS
,
loopEventListener
)
{
'
use strict
'
;
'
use strict
'
;
...
@@ -20,17 +20,17 @@
...
@@ -20,17 +20,17 @@
// Initialize the gadget as soon as it is loaded in memory,
// Initialize the gadget as soon as it is loaded in memory,
// blocking all other methods in itself and its ancestors.
// blocking all other methods in itself and its ancestors.
.
ready
(
function
()
{
.
ready
(
function
()
{
var
gadget
=
this
;
var
gadget
=
this
;
return
gadget
.
setQuery
(
getQueryFromHash
(
window
.
location
.
hash
));
return
gadget
.
setQuery
(
getQueryFromHash
(
window
.
location
.
hash
));
})
})
// Initialize the gadget as soon as it is loaded in the DOM,
// Initialize the gadget as soon as it is loaded in the DOM,
// but only after ready() has finished and stopped blocking.
// but only after ready() has finished and stopped blocking.
.
declareService
(
function
()
{
.
declareService
(
function
()
{
var
gadget
=
this
;
var
gadget
=
this
;
return
loopEventListener
(
window
,
'
hashchange
'
,
false
,
return
loopEventListener
(
window
,
'
hashchange
'
,
false
,
function
()
{
function
()
{
return
gadget
.
setQuery
(
return
gadget
.
setQuery
(
getQueryFromHash
(
window
.
location
.
hash
)
getQueryFromHash
(
window
.
location
.
hash
)
);
);
...
...
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