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
Eugene Shen
todomvc
Commits
41470676
Commit
41470676
authored
Jul 29, 2013
by
Paul Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chaplin-brunch: do real model-level filtering, get rid of stuff.
parent
466147a1
Changes
21
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
89 additions
and
305 deletions
+89
-305
labs/dependency-examples/chaplin-brunch/app/application.coffee
...dependency-examples/chaplin-brunch/app/application.coffee
+2
-8
labs/dependency-examples/chaplin-brunch/app/assets/index.html
.../dependency-examples/chaplin-brunch/app/assets/index.html
+0
-1
labs/dependency-examples/chaplin-brunch/app/controllers/base/controller.coffee
...les/chaplin-brunch/app/controllers/base/controller.coffee
+0
-12
labs/dependency-examples/chaplin-brunch/app/controllers/index-controller.coffee
...es/chaplin-brunch/app/controllers/index-controller.coffee
+23
-3
labs/dependency-examples/chaplin-brunch/app/initialize.coffee
.../dependency-examples/chaplin-brunch/app/initialize.coffee
+1
-1
labs/dependency-examples/chaplin-brunch/app/lib/utils.coffee
labs/dependency-examples/chaplin-brunch/app/lib/utils.coffee
+0
-10
labs/dependency-examples/chaplin-brunch/app/lib/view-helper.coffee
...ndency-examples/chaplin-brunch/app/lib/view-helper.coffee
+0
-39
labs/dependency-examples/chaplin-brunch/app/models/base/collection.coffee
...examples/chaplin-brunch/app/models/base/collection.coffee
+0
-8
labs/dependency-examples/chaplin-brunch/app/models/base/model.coffee
...ency-examples/chaplin-brunch/app/models/base/model.coffee
+0
-3
labs/dependency-examples/chaplin-brunch/app/models/todo.coffee
...dependency-examples/chaplin-brunch/app/models/todo.coffee
+5
-3
labs/dependency-examples/chaplin-brunch/app/models/todos.coffee
...ependency-examples/chaplin-brunch/app/models/todos.coffee
+1
-2
labs/dependency-examples/chaplin-brunch/app/views/base/collection-view.coffee
...ples/chaplin-brunch/app/views/base/collection-view.coffee
+1
-0
labs/dependency-examples/chaplin-brunch/app/views/base/view.coffee
...ndency-examples/chaplin-brunch/app/views/base/view.coffee
+0
-2
labs/dependency-examples/chaplin-brunch/app/views/footer-view.coffee
...ency-examples/chaplin-brunch/app/views/footer-view.coffee
+3
-4
labs/dependency-examples/chaplin-brunch/app/views/header-view.coffee
...ency-examples/chaplin-brunch/app/views/header-view.coffee
+3
-3
labs/dependency-examples/chaplin-brunch/app/views/layout.coffee
...ependency-examples/chaplin-brunch/app/views/layout.coffee
+0
-7
labs/dependency-examples/chaplin-brunch/app/views/todo-view.coffee
...ndency-examples/chaplin-brunch/app/views/todo-view.coffee
+2
-8
labs/dependency-examples/chaplin-brunch/app/views/todos-view.coffee
...dency-examples/chaplin-brunch/app/views/todos-view.coffee
+4
-4
labs/dependency-examples/chaplin-brunch/public/app.js
labs/dependency-examples/chaplin-brunch/public/app.js
+43
-185
labs/dependency-examples/chaplin-brunch/public/app.js.map
labs/dependency-examples/chaplin-brunch/public/app.js.map
+1
-1
labs/dependency-examples/chaplin-brunch/public/index.html
labs/dependency-examples/chaplin-brunch/public/index.html
+0
-1
No files found.
labs/dependency-examples/chaplin-brunch/app/application.coffee
View file @
41470676
mediator
=
require
'mediator'
mediator
=
require
'mediator'
Todos
=
require
'models/todos'
Todos
=
require
'models/todos'
Layout
=
require
'views/layout'
# The application object
# The application object
module
.
exports
=
class
Application
extends
Chaplin
.
Application
module
.
exports
=
class
Application
extends
Chaplin
.
Application
...
@@ -8,13 +7,6 @@ module.exports = class Application extends Chaplin.Application
...
@@ -8,13 +7,6 @@ module.exports = class Application extends Chaplin.Application
# “Controller title – Site title” (see Layout#adjustTitle)
# “Controller title – Site title” (see Layout#adjustTitle)
title
:
'Chaplin • TodoMVC'
title
:
'Chaplin • TodoMVC'
# Override standard layout initializer
# ------------------------------------
initLayout
:
->
# Use an application-specific Layout class. Currently this adds
# no features to the standard Chaplin Layout, it’s an empty placeholder.
@
layout
=
new
Layout
{
@
title
}
# Create additional mediator properties
# Create additional mediator properties
# -------------------------------------
# -------------------------------------
initMediator
:
->
initMediator
:
->
...
@@ -22,6 +14,8 @@ module.exports = class Application extends Chaplin.Application
...
@@ -22,6 +14,8 @@ module.exports = class Application extends Chaplin.Application
mediator
.
user
=
null
mediator
.
user
=
null
# Add additional application-specific properties and methods
# Add additional application-specific properties and methods
mediator
.
todos
=
new
Todos
()
mediator
.
todos
=
new
Todos
()
# If todos are fetched from server, we will need to wait
# for them.
mediator
.
todos
.
fetch
()
mediator
.
todos
.
fetch
()
# Seal the mediator
# Seal the mediator
super
super
labs/dependency-examples/chaplin-brunch/app/assets/index.html
View file @
41470676
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
<!--[if IE]>
<!--[if IE]>
<script src="../../../assets/ie.js"></script>
<script src="../../../assets/ie.js"></script>
<![endif]-->
<![endif]-->
<link
rel=
"stylesheet"
href=
"app.css"
>
<script
src=
"app.js"
></script>
<script
src=
"app.js"
></script>
<script>
require
(
'
initialize
'
);
</script>
<script>
require
(
'
initialize
'
);
</script>
</head>
</head>
...
...
labs/dependency-examples/chaplin-brunch/app/controllers/base/controller.coffee
deleted
100644 → 0
View file @
466147a1
HeaderView
=
require
'views/header-view'
FooterView
=
require
'views/footer-view'
TodosView
=
require
'views/todos-view'
mediator
=
require
'mediator'
module
.
exports
=
class
Controller
extends
Chaplin
.
Controller
beforeAction
:
->
@
compose
'footer'
,
->
params
=
collection
:
mediator
.
todos
@
header
=
new
HeaderView
params
@
footer
=
new
FooterView
params
@
todos
=
new
TodosView
params
labs/dependency-examples/chaplin-brunch/app/controllers/index-controller.coffee
View file @
41470676
Controller
=
require
'./base/controller'
HeaderView
=
require
'views/header-view'
FooterView
=
require
'views/footer-view'
TodosView
=
require
'views/todos-view'
mediator
=
require
'mediator'
module
.
exports
=
class
IndexController
extends
Controller
module
.
exports
=
class
IndexController
extends
Chaplin
.
Controller
# The method is executed before any controller actions.
# We compose structure in order for it to be rendered only once.
beforeAction
:
->
@
compose
'structure'
,
->
params
=
collection
:
mediator
.
todos
@
header
=
new
HeaderView
params
@
footer
=
new
FooterView
params
# On each new load, old @view will be disposed and
# new @view will be created. This is idiomatic Chaplin memory management:
# one controller per screen.
list
:
(
params
)
->
list
:
(
params
)
->
@
publishEvent
'todos:filter'
,
params
.
filterer
?
.
trim
()
?
'all'
filterer
=
params
.
filterer
?
.
trim
()
?
'all'
@
publishEvent
'todos:filter'
,
filterer
@
view
=
new
TodosView
collection
:
mediator
.
todos
,
filterer
:
(
model
)
->
switch
filterer
when
'completed'
then
model
.
get
(
'completed'
)
when
'active'
then
not
model
.
get
(
'completed'
)
else
true
labs/dependency-examples/chaplin-brunch/app/initialize.coffee
View file @
41470676
...
@@ -4,4 +4,4 @@ routes = require 'routes'
...
@@ -4,4 +4,4 @@ routes = require 'routes'
# Initialize the application on DOM ready event.
# Initialize the application on DOM ready event.
$
->
$
->
new
Application
new
Application
controllerSuffix
:
'-controller'
,
pushState
:
no
,
routes
:
routes
controllerSuffix
:
'-controller'
,
pushState
:
false
,
routes
:
routes
labs/dependency-examples/chaplin-brunch/app/lib/utils.coffee
deleted
100644 → 0
View file @
466147a1
# Application-specific utilities
# ------------------------------
# Delegate to Chaplin’s utils module
utils
=
Chaplin
.
utils
.
beget
Chaplin
.
utils
# _(utils).extend
# someMethod: ->
module
.
exports
=
utils
labs/dependency-examples/chaplin-brunch/app/lib/view-helper.coffee
deleted
100644 → 0
View file @
466147a1
mediator
=
require
'mediator'
utils
=
require
'./utils'
# Application-specific view helpers
# ---------------------------------
# http://handlebarsjs.com/#helpers
# Conditional evaluation
# ----------------------
# Choose block by user login status
Handlebars
.
registerHelper
'if_logged_in'
,
(
options
)
->
if
mediator
.
user
options
.
fn
(
this
)
else
options
.
inverse
(
this
)
# Map helpers
# -----------
# Make 'with' behave a little more mustachey
Handlebars
.
registerHelper
'with'
,
(
context
,
options
)
->
if
not
context
or
Handlebars
.
Utils
.
isEmpty
context
options
.
inverse
(
this
)
else
options
.
fn
(
context
)
# Inverse for 'with'
Handlebars
.
registerHelper
'without'
,
(
context
,
options
)
->
inverse
=
options
.
inverse
options
.
inverse
=
options
.
fn
options
.
fn
=
inverse
Handlebars
.
helpers
.
with
.
call
(
this
,
context
,
options
)
# Evaluate block with context being current user
Handlebars
.
registerHelper
'with_user'
,
(
options
)
->
context
=
mediator
.
user
?
.
serialize
()
or
{}
Handlebars
.
helpers
.
with
.
call
(
this
,
context
,
options
)
labs/dependency-examples/chaplin-brunch/app/models/base/collection.coffee
deleted
100644 → 0
View file @
466147a1
Model
=
require
'models/base/model'
module
.
exports
=
class
Collection
extends
Chaplin
.
Collection
# Use the project base model per default, not Chaplin.Model
model
:
Model
# Mixin a synchronization state machine
# _(@prototype).extend Chaplin.SyncMachine
labs/dependency-examples/chaplin-brunch/app/models/base/model.coffee
deleted
100644 → 0
View file @
466147a1
module
.
exports
=
class
Model
extends
Chaplin
.
Model
# Mixin a synchronization state machine
# _(@prototype).extend Chaplin.SyncMachine
labs/dependency-examples/chaplin-brunch/app/models/todo.coffee
View file @
41470676
Model
=
require
'models/base/model'
# It is a very good idea to have base Model / Collection
# e.g. Model = require 'models/base/model'
module
.
exports
=
class
Todo
extends
Model
# But in this particular app since we only have one
# model type, we will inherit directly from Chaplin Model.
module
.
exports
=
class
Todo
extends
Chaplin
.
Model
defaults
:
defaults
:
title
:
''
title
:
''
completed
:
no
completed
:
no
...
...
labs/dependency-examples/chaplin-brunch/app/models/todos.coffee
View file @
41470676
Collection
=
require
'models/base/collection'
Todo
=
require
'models/todo'
Todo
=
require
'models/todo'
module
.
exports
=
class
Todos
extends
Collection
module
.
exports
=
class
Todos
extends
C
haplin
.
C
ollection
model
:
Todo
model
:
Todo
localStorage
:
new
Store
'todos-chaplin'
localStorage
:
new
Store
'todos-chaplin'
...
...
labs/dependency-examples/chaplin-brunch/app/views/base/collection-view.coffee
View file @
41470676
...
@@ -4,3 +4,4 @@ module.exports = class CollectionView extends Chaplin.CollectionView
...
@@ -4,3 +4,4 @@ module.exports = class CollectionView extends Chaplin.CollectionView
# This class doesn’t inherit from the application-specific View class,
# This class doesn’t inherit from the application-specific View class,
# so we need to borrow the method from the View prototype:
# so we need to borrow the method from the View prototype:
getTemplateFunction
:
View
::
getTemplateFunction
getTemplateFunction
:
View
::
getTemplateFunction
useCssAnimation
:
true
labs/dependency-examples/chaplin-brunch/app/views/base/view.coffee
View file @
41470676
require
'lib/view-helper'
# Just load the view helpers, no return value
module
.
exports
=
class
View
extends
Chaplin
.
View
module
.
exports
=
class
View
extends
Chaplin
.
View
# Precompiled templates function initializer.
# Precompiled templates function initializer.
getTemplateFunction
:
->
getTemplateFunction
:
->
...
...
labs/dependency-examples/chaplin-brunch/app/views/footer-view.coffee
View file @
41470676
View
=
require
'
views
/base/view'
View
=
require
'
.
/base/view'
template
=
require
'
views
/templates/footer'
template
=
require
'
.
/templates/footer'
module
.
exports
=
class
FooterView
extends
View
module
.
exports
=
class
FooterView
extends
View
autoRender
:
yes
autoRender
:
true
el
:
'#footer'
el
:
'#footer'
events
:
events
:
'click #clear-completed'
:
'clearCompleted'
'click #clear-completed'
:
'clearCompleted'
...
@@ -16,7 +16,6 @@ module.exports = class FooterView extends View
...
@@ -16,7 +16,6 @@ module.exports = class FooterView extends View
@
renderCounter
()
@
renderCounter
()
updateFilterer
:
(
filterer
)
->
updateFilterer
:
(
filterer
)
->
console
.
log
'updateFilterer'
filterer
=
''
if
filterer
is
'all'
filterer
=
''
if
filterer
is
'all'
@
$
(
'#filters a'
)
@
$
(
'#filters a'
)
.
removeClass
(
'selected'
)
.
removeClass
(
'selected'
)
...
...
labs/dependency-examples/chaplin-brunch/app/views/header-view.coffee
View file @
41470676
View
=
require
'
views
/base/view'
View
=
require
'
.
/base/view'
template
=
require
'
views
/templates/header'
template
=
require
'
.
/templates/header'
module
.
exports
=
class
HeaderView
extends
View
module
.
exports
=
class
HeaderView
extends
View
autoRender
:
yes
autoRender
:
true
el
:
'#header'
el
:
'#header'
events
:
events
:
'keypress #new-todo'
:
'createOnEnter'
'keypress #new-todo'
:
'createOnEnter'
...
...
labs/dependency-examples/chaplin-brunch/app/views/layout.coffee
deleted
100644 → 0
View file @
466147a1
# Layout is the top-level application ‘view’.
module
.
exports
=
class
Layout
extends
Chaplin
.
Layout
listen
:
'todos:filter mediator'
:
'changeFilterer'
changeFilterer
:
(
filterer
=
'all'
)
->
$
(
'#todoapp'
).
attr
'class'
,
"filter-
#{
filterer
}
"
labs/dependency-examples/chaplin-brunch/app/views/todo-view.coffee
View file @
41470676
View
=
require
'
views
/base/view'
View
=
require
'
.
/base/view'
template
=
require
'
views
/templates/todo'
template
=
require
'
.
/templates/todo'
module
.
exports
=
class
TodoView
extends
View
module
.
exports
=
class
TodoView
extends
View
events
:
events
:
...
@@ -15,12 +15,6 @@ module.exports = class TodoView extends View
...
@@ -15,12 +15,6 @@ module.exports = class TodoView extends View
template
:
template
template
:
template
tagName
:
'li'
tagName
:
'li'
render
:
=>
super
# Reset classes, re-add the appropriate ones.
@
$el
.
removeClass
'active completed'
@
$el
.
toggle
@
model
.
get
(
'completed'
)
destroy
:
=>
destroy
:
=>
@
model
.
destroy
()
@
model
.
destroy
()
...
...
labs/dependency-examples/chaplin-brunch/app/views/todos-view.coffee
View file @
41470676
CollectionView
=
require
'
views
/base/collection-view'
CollectionView
=
require
'
.
/base/collection-view'
template
=
require
'
views
/templates/todos'
template
=
require
'
.
/templates/todos'
TodoView
=
require
'
views
/todo-view'
TodoView
=
require
'
.
/todo-view'
module
.
exports
=
class
TodosView
extends
CollectionView
module
.
exports
=
class
TodosView
extends
CollectionView
el
:
'#main'
container
:
'#main'
events
:
events
:
'click #toggle-all'
:
'toggleCompleted'
'click #toggle-all'
:
'toggleCompleted'
itemView
:
TodoView
itemView
:
TodoView
...
...
labs/dependency-examples/chaplin-brunch/public/app.js
View file @
41470676
This diff is collapsed.
Click to expand it.
labs/dependency-examples/chaplin-brunch/public/app.js.map
View file @
41470676
This diff is collapsed.
Click to expand it.
labs/dependency-examples/chaplin-brunch/public/index.html
View file @
41470676
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
<!--[if IE]>
<!--[if IE]>
<script src="../../../assets/ie.js"></script>
<script src="../../../assets/ie.js"></script>
<![endif]-->
<![endif]-->
<link
rel=
"stylesheet"
href=
"app.css"
>
<script
src=
"app.js"
></script>
<script
src=
"app.js"
></script>
<script>
require
(
'
initialize
'
);
</script>
<script>
require
(
'
initialize
'
);
</script>
</head>
</head>
...
...
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