Comments (1)
Short answer: The refactoring technique Inline Temp.
Many underscore
's using contexts with angular
often introduce temporal names, perhaps they could be assigned more practical names, but it maybe just an overhead.
See the following context:
naive version:
js:
var books = [...book's collection];
$scope.booksGroupByDueDate = _.groupBy(books, 'dueDate');
$scope.booksGroupByOwner = _.groupBy(books, 'owner');
$scope.booksGroupByLib = _.groupBy(books, 'lib');
html:
<li ng-repeat="(dueDate, books) in booksGroupByDueDate">
{{dueDate}}
<ul>
<li ng-repeat="book in books">
{{book.name}}
</li>
</ul>
</li>
<li ng-repeat="(owner, books) in booksGroupByOwner">
{{owner}}
<ul>
<li ng-repeat="book in books">
{{book.name}}
</li>
</ul>
</li>
<li ng-repeat="(lib, books) in booksGroupByLib">
{{lib}}
<ul>
<li ng-repeat="book in books">
{{book.name}}
</li>
</ul>
</li>
doesn't it look better:
js:
$scope.books = [...book's collection];
html:
<li ng-repeat="(dueDate, books) in books|groupBy:'dueDate'">
{{dueDate}}
<ul>
<li ng-repeat="book in books">
{{book.name}}
</li>
</ul>
</li>
<li ng-repeat="(owner, books) in books|groupBy:'owner'">
{{owner}}
<ul>
<li ng-repeat="book in books">
{{book.name}}
</li>
</ul>
</li>
<li ng-repeat="(lib, books) in books|groupBy:'lib'">
{{lib}}
<ul>
<li ng-repeat="book in books">
{{book.name}}
</li>
</ul>
</li>
If you use underscore
heavily, you may find many codes could be refactoried in favor of angular's expression
.
To give more examples is OK but need time to coin good examples, maybe community could contribute their usecases.
from angular-underscore.
Related Issues (20)
- How to use it HOT 2
- What license is the angular-underscore project released under? HOT 1
- how to use the filter filter HOT 1
- map as a filter? HOT 1
- load into controller? HOT 9
- Shiv for "sortedIndex"
- Error: $rootScope:infdig Infinite $digest Loop HOT 2
- Newly introduced methods 'indexBy' and 'sample' HOT 1
- Uncaught ReferenceError: _ is not defined HOT 2
- Gem? HOT 5
- Make _.delay(), _.throttle(), and _.debounce() karma friendly HOT 3
- Problem with isolated scope HOT 2
- Registering filters 3 times HOT 1
- Underscore is undefined if I use inside a Directive $scope._
- groupBy filter error HOT 3
- Sorry but... HOT 1
- property predicate
- Error on minify HOT 1
- Consider a bower package? HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-underscore.