Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
angular decorate
Search
damienklinnert
April 09, 2014
Programming
1
77
angular decorate
Use AngularJS' decorate function with ease
damienklinnert
April 09, 2014
Tweet
Share
More Decks by damienklinnert
See All by damienklinnert
Angular Performance Tuning
damienklinnert
4
270
Angular Performance Talk
damienklinnert
0
110
Fight the Rot - Refactor stinky JavaScript
damienklinnert
0
160
modern web apps
damienklinnert
0
110
Become a node package maintainer
damienklinnert
1
87
bootstrap single page apps
damienklinnert
1
300
test your nodejs code
damienklinnert
5
350
Other Decks in Programming
See All in Programming
fs2-io を試してたらバグを見つけて直した話
chencmd
0
250
テストコード書いてみませんか?
onopon
2
230
return文におけるstd::moveについて
onihusube
1
1.3k
Zoneless Testing
rainerhahnekamp
0
120
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
2
130
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
300
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
5
1k
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
130
iOS開発におけるCopilot For XcodeとCode Completion / copilot for xcode
fuyan777
1
270
Beyond ORM
77web
9
1.3k
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
270
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Testing 201, or: Great Expectations
jmmastey
41
7.1k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Building Applications with DynamoDB
mza
91
6.1k
BBQ
matthewcrist
85
9.4k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Agile that works and the tools we love
rasmusluckow
328
21k
YesSQL, Process and Tooling at Scale
rocio
170
14k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Transcript
$PROVIDE .DECORATOR() MODIFYING THE BEHAVIOR OF ANGULARJS' CORE SERVICES
DAMIEN KLINNERT Software Engineer at Small-Improvements damienklinnert.com twitter.com/damienklinnert github.com/damienklinnert
THE DECORATOR PATTERN
None
THE COMPLEX WAY angular.module(moduleName, []) .config(function ($provide) { $provide.decorator(serviceName, function
($delegate) { // modify behavior here return $delegate; }); });
THE SIMPLE WAY angular.module(moduleName, []) .decorate(serviceName, function ($delegate) { //
modify behavior here return $delegate; }); www.github.com/damienklinnert/angular-decorate
ONE APPEND FILE EXTENSION IN $TEMPLATECACHE.GET()
What you have is: <div ng-include="'views/custom-template.html'"></div> What you want is:
<div ng-include="'views/custom-template'"></div>
// Decorator definition angular.module('$templateCache+get', ['ng']) .decorate('$templateCache', function ($delegate) { var
_get = $delegate.get; $delegate.get = function (key) { return _get.call(_get, key + ".html"); }; return $delegate; }); // Use decorator in whole app angular.module('app', ['$templateCache+get', ...])
TWO ADD BASEURL TO EACH $RESOURCE
Make this possible: var users = $resource('http://localhost/users'); console.log(users.baseUrl); // this
is new
// Decorator definition angular.module("$resource+baseUrl", ['ngResource']) .decorate('$resource', function ($delegate) { return
function (baseUrl) { var ret = $delegate.apply(this, arguments); ret.baseUrl = baseUrl; return ret; }; }); // Use decorator in whole app angular.module('app', ['$resource+baseUrl', ...])
THREE INSTRUMENT ANGULAR PERFORMANCE
What can you do with this? angular.module('$rootScope+instrument', []).decorate('$rootScope', function ($delegate)
{ $delegate.__proto__.$watch = function () { ... }; $delegate.__proto__.$apply = function () { ... }; return $delegate; });
THANK YOU RELATED MATERIAL angular-decorate www.github.com/damienklinnert/angular-decorate Hacking Core Directives in
AngularJS http://briantford.com/blog/angular-hacking-core.html Angular $provide http://docs.angularjs.org/api/auto/object/$provide