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
95
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
angular decorate
Use AngularJS' decorate function with ease
damienklinnert
April 09, 2014
More Decks by damienklinnert
See All by damienklinnert
Angular Performance Tuning
damienklinnert
4
280
Angular Performance Talk
damienklinnert
0
140
Fight the Rot - Refactor stinky JavaScript
damienklinnert
0
190
modern web apps
damienklinnert
0
120
Become a node package maintainer
damienklinnert
1
99
bootstrap single page apps
damienklinnert
1
310
test your nodejs code
damienklinnert
5
370
Other Decks in Programming
See All in Programming
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
410
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
210
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
550
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
さぁV100、メモリをお食べ・・・
nilpe
0
150
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.8k
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
250
Oxlintのカスタムルールの現況
syumai
6
1.1k
RTSPクライアントを自作してみた話
simotin13
0
620
A2UI という光を覗いてみる
satohjohn
1
140
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
120
1B+ /day規模のログを管理する技術
broadleaf
0
100
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Ethics towards AI in product and experience design
skipperchong
2
310
GitHub's CSS Performance
jonrohan
1033
470k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
WENDY [Excerpt]
tessaabrams
11
38k
Claude Code のすすめ
schroneko
67
230k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.4k
Abbi's Birthday
coloredviolet
2
8.1k
Amusing Abliteration
ianozsvald
1
210
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
Code Reviewing Like a Champion
maltzj
528
40k
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