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
193752e8
Commit
193752e8
authored
Feb 13, 2014
by
Peter Müller
Committed by
Sindre Sorhus
Feb 13, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close GH-847: Ember: Prevent global leakage of 'use strict' directive.
parent
64af0c87
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
284 additions
and
269 deletions
+284
-269
architecture-examples/emberjs/bower_components/ember-localstorage-adapter/localstorage_adapter.js
...onents/ember-localstorage-adapter/localstorage_adapter.js
+119
-117
architecture-examples/emberjs/js/controllers/todo_controller.js
...ecture-examples/emberjs/js/controllers/todo_controller.js
+52
-51
architecture-examples/emberjs/js/controllers/todos_controller.js
...cture-examples/emberjs/js/controllers/todos_controller.js
+45
-43
architecture-examples/emberjs/js/helpers/pluralize.js
architecture-examples/emberjs/js/helpers/pluralize.js
+8
-6
architecture-examples/emberjs/js/models/todo.js
architecture-examples/emberjs/js/models/todo.js
+7
-5
architecture-examples/emberjs/js/router.js
architecture-examples/emberjs/js/router.js
+34
-32
architecture-examples/emberjs/js/views/edit_todo_view.js
architecture-examples/emberjs/js/views/edit_todo_view.js
+11
-9
architecture-examples/emberjs/js/views/todos_view.js
architecture-examples/emberjs/js/views/todos_view.js
+8
-6
No files found.
architecture-examples/emberjs/bower_components/ember-localstorage-adapter/localstorage_adapter.js
View file @
193752e8
/*global Ember*/
/*global DS*/
'
use strict
'
;
(
function
()
{
'
use strict
'
;
DS
.
LSAdapter
=
DS
.
Adapter
.
extend
(
Ember
.
Evented
,
{
DS
.
LSAdapter
=
DS
.
Adapter
.
extend
(
Ember
.
Evented
,
{
init
:
function
()
{
this
.
_loadData
();
},
init
:
function
()
{
this
.
_loadData
();
},
generateIdForRecord
:
function
()
{
return
Math
.
random
().
toString
(
32
).
slice
(
2
).
substr
(
0
,
5
);
},
generateIdForRecord
:
function
()
{
return
Math
.
random
().
toString
(
32
).
slice
(
2
).
substr
(
0
,
5
);
},
find
:
function
(
store
,
type
,
id
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
return
Ember
.
RSVP
.
resolve
(
Ember
.
copy
(
namespace
.
records
[
id
]));
},
find
:
function
(
store
,
type
,
id
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
return
Ember
.
RSVP
.
resolve
(
Ember
.
copy
(
namespace
.
records
[
id
]));
},
findMany
:
function
(
store
,
type
,
ids
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
var
results
=
[];
for
(
var
i
=
0
;
i
<
ids
.
length
;
i
++
)
{
results
.
push
(
Ember
.
copy
(
namespace
.
records
[
ids
[
i
]]));
}
return
Ember
.
RSVP
.
resolve
(
results
);
},
// Supports queries that look like this:
//
// {
// <property to query>: <value or regex (for strings) to match>,
// ...
// }
//
// Every property added to the query is an "AND" query, not "OR"
//
// Example:
//
// match records with "complete: true" and the name "foo" or "bar"
//
// { complete: true, name: /foo|bar/ }
findQuery
:
function
(
store
,
type
,
query
,
recordArray
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
var
results
=
this
.
query
(
namespace
.
records
,
query
);
return
Ember
.
RSVP
.
resolve
(
results
);
},
query
:
function
(
records
,
query
)
{
var
results
=
[];
var
id
,
record
,
property
,
test
,
push
;
for
(
id
in
records
)
{
record
=
records
[
id
];
for
(
property
in
query
)
{
test
=
query
[
property
];
push
=
false
;
if
(
Object
.
prototype
.
toString
.
call
(
test
)
===
'
[object RegExp]
'
)
{
push
=
test
.
test
(
record
[
property
]);
}
else
{
push
=
record
[
property
]
===
test
;
findMany
:
function
(
store
,
type
,
ids
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
var
results
=
[];
for
(
var
i
=
0
;
i
<
ids
.
length
;
i
++
)
{
results
.
push
(
Ember
.
copy
(
namespace
.
records
[
ids
[
i
]]));
}
return
Ember
.
RSVP
.
resolve
(
results
);
},
// Supports queries that look like this:
//
// {
// <property to query>: <value or regex (for strings) to match>,
// ...
// }
//
// Every property added to the query is an "AND" query, not "OR"
//
// Example:
//
// match records with "complete: true" and the name "foo" or "bar"
//
// { complete: true, name: /foo|bar/ }
findQuery
:
function
(
store
,
type
,
query
,
recordArray
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
var
results
=
this
.
query
(
namespace
.
records
,
query
);
return
Ember
.
RSVP
.
resolve
(
results
);
},
query
:
function
(
records
,
query
)
{
var
results
=
[];
var
id
,
record
,
property
,
test
,
push
;
for
(
id
in
records
)
{
record
=
records
[
id
];
for
(
property
in
query
)
{
test
=
query
[
property
];
push
=
false
;
if
(
Object
.
prototype
.
toString
.
call
(
test
)
===
'
[object RegExp]
'
)
{
push
=
test
.
test
(
record
[
property
]);
}
else
{
push
=
record
[
property
]
===
test
;
}
}
if
(
push
)
{
results
.
push
(
record
);
}
}
if
(
push
)
{
results
.
push
(
record
);
return
results
;
},
findAll
:
function
(
store
,
type
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
var
results
=
[];
for
(
var
id
in
namespace
.
records
)
{
results
.
push
(
Ember
.
copy
(
namespace
.
records
[
id
]));
}
return
Ember
.
RSVP
.
resolve
(
results
);
},
createRecord
:
function
(
store
,
type
,
record
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
this
.
_addRecordToNamespace
(
namespace
,
record
);
this
.
_saveData
();
return
Ember
.
RSVP
.
resolve
();
},
updateRecord
:
function
(
store
,
type
,
record
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
var
id
=
record
.
get
(
'
id
'
);
namespace
.
records
[
id
]
=
record
.
toJSON
({
includeId
:
true
});
this
.
_saveData
();
return
Ember
.
RSVP
.
resolve
();
},
deleteRecord
:
function
(
store
,
type
,
record
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
var
id
=
record
.
get
(
'
id
'
);
delete
namespace
.
records
[
id
];
this
.
_saveData
();
return
Ember
.
RSVP
.
resolve
();
},
// private
_getNamespace
:
function
()
{
return
this
.
namespace
||
'
DS.LSAdapter
'
;
},
_loadData
:
function
()
{
var
storage
=
localStorage
.
getItem
(
this
.
_getNamespace
());
this
.
_data
=
storage
?
JSON
.
parse
(
storage
)
:
{};
},
_saveData
:
function
()
{
localStorage
.
setItem
(
this
.
_getNamespace
(),
JSON
.
stringify
(
this
.
_data
));
},
_namespaceForType
:
function
(
type
)
{
var
namespace
=
type
.
url
||
type
.
toString
();
return
this
.
_data
[
namespace
]
||
(
this
.
_data
[
namespace
]
=
{
records
:
{}}
);
},
_addRecordToNamespace
:
function
(
namespace
,
record
)
{
var
data
=
record
.
serialize
({
includeId
:
true
});
namespace
.
records
[
data
.
id
]
=
data
;
}
return
results
;
},
findAll
:
function
(
store
,
type
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
var
results
=
[];
for
(
var
id
in
namespace
.
records
)
{
results
.
push
(
Ember
.
copy
(
namespace
.
records
[
id
]));
}
return
Ember
.
RSVP
.
resolve
(
results
);
},
createRecord
:
function
(
store
,
type
,
record
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
this
.
_addRecordToNamespace
(
namespace
,
record
);
this
.
_saveData
();
return
Ember
.
RSVP
.
resolve
();
},
updateRecord
:
function
(
store
,
type
,
record
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
var
id
=
record
.
get
(
'
id
'
);
namespace
.
records
[
id
]
=
record
.
toJSON
({
includeId
:
true
});
this
.
_saveData
();
return
Ember
.
RSVP
.
resolve
();
},
deleteRecord
:
function
(
store
,
type
,
record
)
{
var
namespace
=
this
.
_namespaceForType
(
type
);
var
id
=
record
.
get
(
'
id
'
);
delete
namespace
.
records
[
id
];
this
.
_saveData
();
return
Ember
.
RSVP
.
resolve
();
},
// private
_getNamespace
:
function
()
{
return
this
.
namespace
||
'
DS.LSAdapter
'
;
},
_loadData
:
function
()
{
var
storage
=
localStorage
.
getItem
(
this
.
_getNamespace
());
this
.
_data
=
storage
?
JSON
.
parse
(
storage
)
:
{};
},
_saveData
:
function
()
{
localStorage
.
setItem
(
this
.
_getNamespace
(),
JSON
.
stringify
(
this
.
_data
));
},
_namespaceForType
:
function
(
type
)
{
var
namespace
=
type
.
url
||
type
.
toString
();
return
this
.
_data
[
namespace
]
||
(
this
.
_data
[
namespace
]
=
{
records
:
{}}
);
},
_addRecordToNamespace
:
function
(
namespace
,
record
)
{
var
data
=
record
.
serialize
({
includeId
:
true
});
namespace
.
records
[
data
.
id
]
=
data
;
}
});
});
})();
architecture-examples/emberjs/js/controllers/todo_controller.js
View file @
193752e8
/*global Todos, Ember */
'
use strict
'
;
Todos
.
TodoController
=
Ember
.
ObjectController
.
extend
({
isEditing
:
false
,
// We use the bufferedTitle to store the original value of
// the model's title so that we can roll it back later in the
// `cancelEditing` action.
bufferedTitle
:
Ember
.
computed
.
oneWay
(
'
title
'
),
actions
:
{
editTodo
:
function
()
{
this
.
set
(
'
isEditing
'
,
true
);
},
doneEditing
:
function
()
{
var
bufferedTitle
=
this
.
get
(
'
bufferedTitle
'
).
trim
();
if
(
Ember
.
isEmpty
(
bufferedTitle
))
{
// The `doneEditing` action gets sent twice when the user hits
// enter (once via 'insert-newline' and once via 'focus-out').
//
// We debounce our call to 'removeTodo' so that it only gets
// made once.
Ember
.
run
.
debounce
(
this
,
'
removeTodo
'
,
0
);
}
else
{
var
todo
=
this
.
get
(
'
model
'
);
todo
.
set
(
'
title
'
,
bufferedTitle
);
todo
.
save
();
(
function
()
{
'
use strict
'
;
Todos
.
TodoController
=
Ember
.
ObjectController
.
extend
({
isEditing
:
false
,
// We use the bufferedTitle to store the original value of
// the model's title so that we can roll it back later in the
// `cancelEditing` action.
bufferedTitle
:
Ember
.
computed
.
oneWay
(
'
title
'
),
actions
:
{
editTodo
:
function
()
{
this
.
set
(
'
isEditing
'
,
true
);
},
doneEditing
:
function
()
{
var
bufferedTitle
=
this
.
get
(
'
bufferedTitle
'
).
trim
();
if
(
Ember
.
isEmpty
(
bufferedTitle
))
{
// The `doneEditing` action gets sent twice when the user hits
// enter (once via 'insert-newline' and once via 'focus-out').
//
// We debounce our call to 'removeTodo' so that it only gets
// made once.
Ember
.
run
.
debounce
(
this
,
'
removeTodo
'
,
0
);
}
else
{
var
todo
=
this
.
get
(
'
model
'
);
todo
.
set
(
'
title
'
,
bufferedTitle
);
todo
.
save
();
}
// Re-set our newly edited title to persist its trimmed version
this
.
set
(
'
bufferedTitle
'
,
bufferedTitle
);
this
.
set
(
'
isEditing
'
,
false
);
},
cancelEditing
:
function
()
{
this
.
set
(
'
bufferedTitle
'
,
this
.
get
(
'
title
'
));
this
.
set
(
'
isEditing
'
,
false
);
},
removeTodo
:
function
()
{
this
.
removeTodo
();
}
// Re-set our newly edited title to persist its trimmed version
this
.
set
(
'
bufferedTitle
'
,
bufferedTitle
);
this
.
set
(
'
isEditing
'
,
false
);
},
cancelEditing
:
function
()
{
this
.
set
(
'
bufferedTitle
'
,
this
.
get
(
'
title
'
));
this
.
set
(
'
isEditing
'
,
false
);
},
removeTodo
:
function
()
{
this
.
removeTodo
();
}
},
var
todo
=
this
.
get
(
'
model
'
);
removeTodo
:
function
()
{
var
todo
=
this
.
get
(
'
model
'
);
todo
.
deleteRecord
();
todo
.
save
();
},
todo
.
deleteRecord
();
todo
.
save
();
},
saveWhenCompleted
:
function
()
{
this
.
get
(
'
model
'
).
save
();
}.
observes
(
'
isCompleted
'
)
});
saveWhenCompleted
:
function
()
{
this
.
get
(
'
model
'
).
save
();
}.
observes
(
'
isCompleted
'
)
});
})();
architecture-examples/emberjs/js/controllers/todos_controller.js
View file @
193752e8
/*global Todos, Ember */
'
use strict
'
;
Todos
.
TodosController
=
Ember
.
ArrayController
.
extend
({
actions
:
{
createTodo
:
function
()
{
var
title
,
todo
;
// Get the todo title set by the "New Todo" text field
title
=
this
.
get
(
'
newTitle
'
).
trim
();
if
(
!
title
)
{
return
;
}
// Create the new Todo model
todo
=
this
.
store
.
createRecord
(
'
todo
'
,
{
title
:
title
,
isCompleted
:
false
});
todo
.
save
();
// Clear the "New Todo" text field
this
.
set
(
'
newTitle
'
,
''
);
},
clearCompleted
:
function
()
{
var
completed
=
this
.
get
(
'
completed
'
);
completed
.
invoke
(
'
deleteRecord
'
);
completed
.
invoke
(
'
save
'
);
(
function
()
{
'
use strict
'
;
Todos
.
TodosController
=
Ember
.
ArrayController
.
extend
({
actions
:
{
createTodo
:
function
()
{
var
title
,
todo
;
// Get the todo title set by the "New Todo" text field
title
=
this
.
get
(
'
newTitle
'
).
trim
();
if
(
!
title
)
{
return
;
}
// Create the new Todo model
todo
=
this
.
store
.
createRecord
(
'
todo
'
,
{
title
:
title
,
isCompleted
:
false
});
todo
.
save
();
// Clear the "New Todo" text field
this
.
set
(
'
newTitle
'
,
''
);
},
clearCompleted
:
function
()
{
var
completed
=
this
.
get
(
'
completed
'
);
completed
.
invoke
(
'
deleteRecord
'
);
completed
.
invoke
(
'
save
'
);
},
},
},
/* properties */
/* properties */
remaining
:
Ember
.
computed
.
filterBy
(
'
content
'
,
'
isCompleted
'
,
false
),
completed
:
Ember
.
computed
.
filterBy
(
'
content
'
,
'
isCompleted
'
,
true
),
remaining
:
Ember
.
computed
.
filterBy
(
'
content
'
,
'
isCompleted
'
,
false
),
completed
:
Ember
.
computed
.
filterBy
(
'
content
'
,
'
isCompleted
'
,
true
),
allAreDone
:
function
(
key
,
value
)
{
if
(
value
!==
undefined
)
{
this
.
setEach
(
'
isCompleted
'
,
value
);
return
value
;
}
else
{
var
length
=
this
.
get
(
'
length
'
);
var
completedLength
=
this
.
get
(
'
completed.length
'
);
allAreDone
:
function
(
key
,
value
)
{
if
(
value
!==
undefined
)
{
this
.
setEach
(
'
isCompleted
'
,
value
);
return
value
;
}
else
{
var
length
=
this
.
get
(
'
length
'
);
var
completedLength
=
this
.
get
(
'
completed.length
'
);
return
length
>
0
&&
length
===
completedLength
;
}
}.
property
(
'
length
'
,
'
completed.length
'
)
});
return
length
>
0
&&
length
===
completedLength
;
}
}.
property
(
'
length
'
,
'
completed.length
'
)
});
})();
architecture-examples/emberjs/js/helpers/pluralize.js
View file @
193752e8
/*global Todos, Ember */
'
use strict
'
;
(
function
()
{
'
use strict
'
;
Ember
.
Handlebars
.
helper
(
'
pluralize
'
,
function
(
singular
,
count
)
{
/* From Ember-Data */
var
inflector
=
new
Ember
.
Inflector
(
Ember
.
Inflector
.
defaultRules
);
Ember
.
Handlebars
.
helper
(
'
pluralize
'
,
function
(
singular
,
count
)
{
/* From Ember-Data */
var
inflector
=
new
Ember
.
Inflector
(
Ember
.
Inflector
.
defaultRules
);
return
count
===
1
?
singular
:
inflector
.
pluralize
(
singular
);
});
return
count
===
1
?
singular
:
inflector
.
pluralize
(
singular
);
});
})();
architecture-examples/emberjs/js/models/todo.js
View file @
193752e8
/*global Todos, DS */
'
use strict
'
;
(
function
()
{
'
use strict
'
;
Todos
.
Todo
=
DS
.
Model
.
extend
({
title
:
DS
.
attr
(
'
string
'
),
isCompleted
:
DS
.
attr
(
'
boolean
'
)
});
Todos
.
Todo
=
DS
.
Model
.
extend
({
title
:
DS
.
attr
(
'
string
'
),
isCompleted
:
DS
.
attr
(
'
boolean
'
)
});
})();
architecture-examples/emberjs/js/router.js
View file @
193752e8
/*global Ember, Todos */
'
use strict
'
;
(
function
()
{
'
use strict
'
;
Todos
.
Router
.
map
(
function
()
{
this
.
resource
(
'
todos
'
,
{
path
:
'
/
'
},
function
()
{
this
.
route
(
'
active
'
);
this
.
route
(
'
completed
'
);
Todos
.
Router
.
map
(
function
()
{
this
.
resource
(
'
todos
'
,
{
path
:
'
/
'
},
function
()
{
this
.
route
(
'
active
'
);
this
.
route
(
'
completed
'
);
});
});
});
Todos
.
TodosRoute
=
Ember
.
Route
.
extend
({
model
:
function
()
{
return
this
.
store
.
find
(
'
todo
'
);
}
});
Todos
.
TodosRoute
=
Ember
.
Route
.
extend
({
model
:
function
()
{
return
this
.
store
.
find
(
'
todo
'
);
}
});
Todos
.
TodosIndexRoute
=
Ember
.
Route
.
extend
({
setupController
:
function
()
{
this
.
controllerFor
(
'
todos
'
).
set
(
'
filteredTodos
'
,
this
.
modelFor
(
'
todos
'
));
}
});
Todos
.
TodosIndexRoute
=
Ember
.
Route
.
extend
({
setupController
:
function
()
{
this
.
controllerFor
(
'
todos
'
).
set
(
'
filteredTodos
'
,
this
.
modelFor
(
'
todos
'
));
}
});
Todos
.
TodosActiveRoute
=
Ember
.
Route
.
extend
({
setupController
:
function
()
{
var
todos
=
this
.
store
.
filter
(
'
todo
'
,
function
(
todo
)
{
return
!
todo
.
get
(
'
isCompleted
'
);
});
Todos
.
TodosActiveRoute
=
Ember
.
Route
.
extend
({
setupController
:
function
()
{
var
todos
=
this
.
store
.
filter
(
'
todo
'
,
function
(
todo
)
{
return
!
todo
.
get
(
'
isCompleted
'
);
});
this
.
controllerFor
(
'
todos
'
).
set
(
'
filteredTodos
'
,
todos
);
}
});
this
.
controllerFor
(
'
todos
'
).
set
(
'
filteredTodos
'
,
todos
);
}
});
Todos
.
TodosCompletedRoute
=
Ember
.
Route
.
extend
({
setupController
:
function
()
{
var
todos
=
this
.
store
.
filter
(
'
todo
'
,
function
(
todo
)
{
return
todo
.
get
(
'
isCompleted
'
);
});
Todos
.
TodosCompletedRoute
=
Ember
.
Route
.
extend
({
setupController
:
function
()
{
var
todos
=
this
.
store
.
filter
(
'
todo
'
,
function
(
todo
)
{
return
todo
.
get
(
'
isCompleted
'
);
});
this
.
controllerFor
(
'
todos
'
).
set
(
'
filteredTodos
'
,
todos
);
}
});
this
.
controllerFor
(
'
todos
'
).
set
(
'
filteredTodos
'
,
todos
);
}
});
})();
architecture-examples/emberjs/js/views/edit_todo_view.js
View file @
193752e8
/*global Todos, Ember */
'
use strict
'
;
(
function
()
{
'
use strict
'
;
Todos
.
EditTodoView
=
Ember
.
TextField
.
extend
({
focusOnInsert
:
function
()
{
// Re-set input value to get rid of a reduntant text selection
this
.
$
().
val
(
this
.
$
().
val
());
this
.
$
().
focus
();
}.
on
(
'
didInsertElement
'
)
});
Todos
.
EditTodoView
=
Ember
.
TextField
.
extend
({
focusOnInsert
:
function
()
{
// Re-set input value to get rid of a reduntant text selection
this
.
$
().
val
(
this
.
$
().
val
());
this
.
$
().
focus
();
}.
on
(
'
didInsertElement
'
)
});
Ember
.
Handlebars
.
helper
(
'
edit-todo
'
,
Todos
.
EditTodoView
);
Ember
.
Handlebars
.
helper
(
'
edit-todo
'
,
Todos
.
EditTodoView
);
})();
architecture-examples/emberjs/js/views/todos_view.js
View file @
193752e8
/*global Todos, Ember */
'
use strict
'
;
(
function
()
{
'
use strict
'
;
Todos
.
TodosView
=
Ember
.
View
.
extend
({
focusInput
:
function
()
{
this
.
$
(
'
#new-todo
'
).
focus
();
}.
on
(
'
didInsertElement
'
)
});
Todos
.
TodosView
=
Ember
.
View
.
extend
({
focusInput
:
function
()
{
this
.
$
(
'
#new-todo
'
).
focus
();
}.
on
(
'
didInsertElement
'
)
});
})();
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