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
81897ce5
Commit
81897ce5
authored
Dec 22, 2015
by
dmitriz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
angularjs-perf: Wrap into anonymous functions
parent
a960f9a4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
150 additions
and
140 deletions
+150
-140
examples/angularjs-perf/js/app.js
examples/angularjs-perf/js/app.js
+9
-7
examples/angularjs-perf/js/controllers/todoCtrl.js
examples/angularjs-perf/js/controllers/todoCtrl.js
+84
-82
examples/angularjs-perf/js/directives/todoEscape.js
examples/angularjs-perf/js/directives/todoEscape.js
+21
-19
examples/angularjs-perf/js/directives/todoFocus.js
examples/angularjs-perf/js/directives/todoFocus.js
+18
-16
examples/angularjs-perf/js/services/todoStorage.js
examples/angularjs-perf/js/services/todoStorage.js
+18
-16
No files found.
examples/angularjs-perf/js/app.js
View file @
81897ce5
/*global angular */
/*jshint unused:false */
'
use strict
'
;
(
function
()
{
'
use strict
'
;
/**
* The main TodoMVC app module that pulls all dependency modules declared in same named files
*
* @type {angular.Module}
*/
angular
.
module
(
'
todomvc
'
,
[
'
todoCtrl
'
,
'
todoEscape
'
,
'
todoStorage
'
]);
/**
* The main TodoMVC app module that pulls all dependency modules declared in same named files
*
* @type {angular.Module}
*/
angular
.
module
(
'
todomvc
'
,
[
'
todoCtrl
'
,
'
todoEscape
'
,
'
todoStorage
'
]);
})();
examples/angularjs-perf/js/controllers/todoCtrl.js
View file @
81897ce5
/*global angular */
'
use strict
'
;
(
function
()
{
'
use strict
'
;
angular
.
module
(
'
todoCtrl
'
,
[])
angular
.
module
(
'
todoCtrl
'
,
[])
/**
* The main controller for the app. The controller:
* - retrieves and persists the model via the todoStorage service
* - exposes the model to the template and provides event handlers
*/
.
controller
(
'
TodoCtrl
'
,
function
TodoCtrl
(
$scope
,
$location
,
$filter
,
todoStorage
)
{
var
todos
=
$scope
.
todos
=
todoStorage
.
get
();
$scope
.
newTodo
=
''
;
$scope
.
remainingCount
=
$filter
(
'
filter
'
)(
todos
,
{
completed
:
false
}).
length
;
$scope
.
editedTodo
=
null
;
if
(
$location
.
path
()
===
''
)
{
$location
.
path
(
'
/
'
);
}
$scope
.
location
=
$location
;
$scope
.
$watch
(
'
location.path()
'
,
function
(
path
)
{
$scope
.
statusFilter
=
{
'
/active
'
:
{
completed
:
false
},
'
/completed
'
:
{
completed
:
true
}
}[
path
];
});
$scope
.
$watch
(
'
remainingCount == 0
'
,
function
(
val
)
{
$scope
.
allChecked
=
val
;
});
$scope
.
addTodo
=
function
()
{
var
newTodo
=
$scope
.
newTodo
.
trim
();
if
(
newTodo
.
length
===
0
)
{
return
;
}
todos
.
push
({
title
:
newTodo
,
completed
:
false
});
todoStorage
.
put
(
todos
);
/**
* The main controller for the app. The controller:
* - retrieves and persists the model via the todoStorage service
* - exposes the model to the template and provides event handlers
*/
.
controller
(
'
TodoCtrl
'
,
function
TodoCtrl
(
$scope
,
$location
,
$filter
,
todoStorage
)
{
var
todos
=
$scope
.
todos
=
todoStorage
.
get
();
$scope
.
newTodo
=
''
;
$scope
.
remainingCount
++
;
};
$scope
.
editTodo
=
function
(
todo
)
{
$scope
.
editedTodo
=
todo
;
// Clone the original todo to restore it on demand.
$scope
.
originalTodo
=
angular
.
extend
({},
todo
);
};
$scope
.
doneEditing
=
function
(
todo
)
{
$scope
.
remainingCount
=
$filter
(
'
filter
'
)(
todos
,
{
completed
:
false
}).
length
;
$scope
.
editedTodo
=
null
;
todo
.
title
=
todo
.
title
.
trim
();
if
(
!
todo
.
title
)
{
$
scope
.
removeTodo
(
todo
);
if
(
$location
.
path
()
===
''
)
{
$
location
.
path
(
'
/
'
);
}
todoStorage
.
put
(
todos
);
};
$scope
.
revertEditing
=
function
(
todo
)
{
todos
[
todos
.
indexOf
(
todo
)]
=
$scope
.
originalTodo
;
$scope
.
doneEditing
(
$scope
.
originalTodo
);
};
$scope
.
location
=
$location
;
$scope
.
removeTodo
=
function
(
todo
)
{
$scope
.
remainingCount
-=
todo
.
completed
?
0
:
1
;
todos
.
splice
(
todos
.
indexOf
(
todo
),
1
);
todoStorage
.
put
(
todos
);
};
$scope
.
todoCompleted
=
function
(
todo
)
{
$scope
.
remainingCount
+=
todo
.
completed
?
-
1
:
1
;
todoStorage
.
put
(
todos
);
};
$scope
.
clearCompletedTodos
=
function
()
{
$scope
.
todos
=
todos
=
todos
.
filter
(
function
(
val
)
{
return
!
val
.
completed
;
$scope
.
$watch
(
'
location.path()
'
,
function
(
path
)
{
$scope
.
statusFilter
=
{
'
/active
'
:
{
completed
:
false
},
'
/completed
'
:
{
completed
:
true
}
}[
path
];
});
todoStorage
.
put
(
todos
);
};
$scope
.
markAll
=
function
(
completed
)
{
todos
.
forEach
(
function
(
todo
)
{
todo
.
completed
=
completed
;
$scope
.
$watch
(
'
remainingCount == 0
'
,
function
(
val
)
{
$scope
.
allChecked
=
val
;
});
$scope
.
remainingCount
=
completed
?
0
:
todos
.
length
;
todoStorage
.
put
(
todos
);
};
});
$scope
.
addTodo
=
function
()
{
var
newTodo
=
$scope
.
newTodo
.
trim
();
if
(
newTodo
.
length
===
0
)
{
return
;
}
todos
.
push
({
title
:
newTodo
,
completed
:
false
});
todoStorage
.
put
(
todos
);
$scope
.
newTodo
=
''
;
$scope
.
remainingCount
++
;
};
$scope
.
editTodo
=
function
(
todo
)
{
$scope
.
editedTodo
=
todo
;
// Clone the original todo to restore it on demand.
$scope
.
originalTodo
=
angular
.
extend
({},
todo
);
};
$scope
.
doneEditing
=
function
(
todo
)
{
$scope
.
editedTodo
=
null
;
todo
.
title
=
todo
.
title
.
trim
();
if
(
!
todo
.
title
)
{
$scope
.
removeTodo
(
todo
);
}
todoStorage
.
put
(
todos
);
};
$scope
.
revertEditing
=
function
(
todo
)
{
todos
[
todos
.
indexOf
(
todo
)]
=
$scope
.
originalTodo
;
$scope
.
doneEditing
(
$scope
.
originalTodo
);
};
$scope
.
removeTodo
=
function
(
todo
)
{
$scope
.
remainingCount
-=
todo
.
completed
?
0
:
1
;
todos
.
splice
(
todos
.
indexOf
(
todo
),
1
);
todoStorage
.
put
(
todos
);
};
$scope
.
todoCompleted
=
function
(
todo
)
{
$scope
.
remainingCount
+=
todo
.
completed
?
-
1
:
1
;
todoStorage
.
put
(
todos
);
};
$scope
.
clearCompletedTodos
=
function
()
{
$scope
.
todos
=
todos
=
todos
.
filter
(
function
(
val
)
{
return
!
val
.
completed
;
});
todoStorage
.
put
(
todos
);
};
$scope
.
markAll
=
function
(
completed
)
{
todos
.
forEach
(
function
(
todo
)
{
todo
.
completed
=
completed
;
});
$scope
.
remainingCount
=
completed
?
0
:
todos
.
length
;
todoStorage
.
put
(
todos
);
};
});
})();
examples/angularjs-perf/js/directives/todoEscape.js
View file @
81897ce5
/*global angular */
'
use strict
'
;
(
function
()
{
'
use strict
'
;
angular
.
module
(
'
todoEscape
'
,
[])
angular
.
module
(
'
todoEscape
'
,
[])
/**
* Directive that executes an expression when the element it is applied to gets
* an `escape` keydown event.
*/
.
directive
(
'
todoEscape
'
,
function
()
{
var
ESCAPE_KEY
=
27
;
return
function
(
scope
,
elem
,
attrs
)
{
elem
.
bind
(
'
keydown
'
,
function
(
event
)
{
if
(
event
.
keyCode
===
ESCAPE_KEY
)
{
scope
.
$apply
(
attrs
.
todoEscape
);
}
});
/**
* Directive that executes an expression when the element it is applied to gets
* an `escape` keydown event.
*/
.
directive
(
'
todoEscape
'
,
function
()
{
var
ESCAPE_KEY
=
27
;
return
function
(
scope
,
elem
,
attrs
)
{
elem
.
bind
(
'
keydown
'
,
function
(
event
)
{
if
(
event
.
keyCode
===
ESCAPE_KEY
)
{
scope
.
$apply
(
attrs
.
todoEscape
);
}
});
scope
.
$on
(
'
$destroy
'
,
function
()
{
elem
.
unbind
(
'
keydown
'
);
});
};
});
scope
.
$on
(
'
$destroy
'
,
function
()
{
elem
.
unbind
(
'
keydown
'
);
});
};
});
})();
examples/angularjs-perf/js/directives/todoFocus.js
View file @
81897ce5
/*global angular */
'
use strict
'
;
(
function
()
{
'
use strict
'
;
angular
.
module
(
'
todoFocus
'
,
[])
angular
.
module
(
'
todoFocus
'
,
[])
/**
* Directive that places focus on the element it is applied to when the expression it binds to evaluates to true
*/
.
directive
(
'
todoFocus
'
,
function
(
$timeout
)
{
return
function
(
scope
,
elem
,
attrs
)
{
scope
.
$watch
(
attrs
.
todoFocus
,
function
(
newVal
)
{
if
(
newVal
)
{
$timeout
(
function
()
{
elem
[
0
].
focus
();
},
0
,
false
);
}
});
};
});
/**
* Directive that places focus on the element it is applied to when the expression it binds to evaluates to true
*/
.
directive
(
'
todoFocus
'
,
function
(
$timeout
)
{
return
function
(
scope
,
elem
,
attrs
)
{
scope
.
$watch
(
attrs
.
todoFocus
,
function
(
newVal
)
{
if
(
newVal
)
{
$timeout
(
function
()
{
elem
[
0
].
focus
();
},
0
,
false
);
}
});
};
});
})();
examples/angularjs-perf/js/services/todoStorage.js
View file @
81897ce5
/*global angular */
'
use strict
'
;
(
function
()
{
'
use strict
'
;
angular
.
module
(
'
todoStorage
'
,
[])
angular
.
module
(
'
todoStorage
'
,
[])
/**
* Services that persists and retrieves TODOs from localStorage
*/
.
factory
(
'
todoStorage
'
,
function
()
{
var
STORAGE_ID
=
'
todos-angularjs-perf
'
;
/**
* Services that persists and retrieves TODOs from localStorage
*/
.
factory
(
'
todoStorage
'
,
function
()
{
var
STORAGE_ID
=
'
todos-angularjs-perf
'
;
return
{
get
:
function
()
{
return
JSON
.
parse
(
localStorage
.
getItem
(
STORAGE_ID
)
||
'
[]
'
);
},
return
{
get
:
function
()
{
return
JSON
.
parse
(
localStorage
.
getItem
(
STORAGE_ID
)
||
'
[]
'
);
},
put
:
function
(
todos
)
{
localStorage
.
setItem
(
STORAGE_ID
,
JSON
.
stringify
(
todos
));
}
};
});
put
:
function
(
todos
)
{
localStorage
.
setItem
(
STORAGE_ID
,
JSON
.
stringify
(
todos
));
}
};
});
})();
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