Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

One-time Binding & $digest

14,753 views

Published on

ng-japan 2015 LT資料です。
One-time Bindingと$digestについて簡単にお話しました。

LIGブログでこの内容をまとめました。
http://liginc.co.jp/web/js/other-js/153751

Published in: Technology
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

One-time Binding & $digest

  1. 1. One$%me'Binding'&'$digest ∼ng#japan'2015∼ ©"2014"LIG"INC."@frontainer
  2. 2. 自己紹介 林 優一!@frontainer フロントエンドエンジニア AngularJS関連の登壇歴 • AngularJSの今とこれから+,+フロントエ ンドエンジニア座談会+」 • AngularJS+ディレクティブ・パターン • 受託開発でのAngularJS+ ©"2014"LIG"INC."@frontainer
  3. 3. One$%me'Bindingとは バインディングを1度しか評価しないようにする機能 One$%me'bindingはAngularJS1.3から追加'(1.2以前の場合は「BindOnce」などのモジュールを使う) ©"2014"LIG"INC."@frontainer
  4. 4. 使い方 {{::name}} <div ng-repeat="user in ::users"></div> ex)$demo1 ©"2014"LIG"INC."@frontainer
  5. 5. 例外 An#expression#that#starts#with#::#is#considered#a#one23me# expression.#One23me#expressions#will#stop#recalcula3ng#once#they# are#stable,#which#happens#a=er#the#first#digest#if#the#expression# result#is#a#non2undefined#value#(see#value#stabiliza3on#algorithm# below). !!"AngularJS"Developer"Guide"!"Expressions ©"2014"LIG"INC."@frontainer
  6. 6. 簡単に言うと・・・ • 値がundefinedでなければ最初の$digestで値が保持される。 • 逆にいうとundefinedである間は値が固定されない。 ex)$demo2 ©"2014"LIG"INC."@frontainer
  7. 7. Watch数の違いをサンプルで見る 500件の簡単なユーザーデータを持つJSONをng)repeatでループして表示させる [ { "id": 1, "name": "User1", "value": 100 }, ... ] ©"2014"LIG"INC."@frontainer
  8. 8. JavaScript angular.module('app').controller('RootCtrl',[ '$scope', 'USERS', function($scope,USERS) { $scope.users = USERS; } ]); ©"2014"LIG"INC."@frontainer
  9. 9. 特に何もしない場合 <div ng-controller="RootCtrl"> <ul> <li ng-repeat="user in users"> <div>{{user.id}} - {{user.name}}</div> <div>{{user.value}}</div> </li> </ul> </div> ex)$demo3 ©"2014"LIG"INC."@frontainer
  10. 10. ©"2014"LIG"INC."@frontainer
  11. 11. 配列に付けた場合 <div ng-controller="RootCtrl"> <ul> <li ng-repeat="user in ::users"> <div>{{user.id}} - {{user.name}}</div> <div>{{user.value}}</div> </li> </ul> </div> ex)$demo3)2 ©"2014"LIG"INC."@frontainer
  12. 12. ©"2014"LIG"INC."@frontainer
  13. 13. 配列内のプロパティに付けた場合 <div ng-controller="RootCtrl"> <ul> <li ng-repeat="user in users"> <div>{{::user.id}} - {{::user.name}}</div> <div>{{::user.value}}</div> </li> </ul> </div> ex)$demo3)3 ©"2014"LIG"INC."@frontainer
  14. 14. ©"2014"LIG"INC."@frontainer
  15. 15. 配列と配列内のプロパティに付けた場合 <div ng-controller="RootCtrl"> <ul> <li ng-repeat="user in ::users"> <div>{{::user.id}} - {{::user.name}}</div> <div>{{::user.value}}</div> </li> </ul> </div> ex)$demo3)4 ©"2014"LIG"INC."@frontainer
  16. 16. ©"2014"LIG"INC."@frontainer
  17. 17. One$%me'Bindingをしないと・・・ Scopeで他の値を書き換えた時にも影響を及ぼす。 ©"2014"LIG"INC."@frontainer
  18. 18. $digestでのチェック回数 • demo1[特に何もしない場合]:*1503回 • demo*2[配列に付けた場合]:*1502回 • demo*3[配列内のプロパティに付けた場合]:*3回 • demo*4[配列と配列内のプロパティに付けた場合]:*2回 ※!consoleに$digestループ実行回数が出力されます ex)$demo4$demo4)2$demo4)3$demo4)4 ©"2014"LIG"INC."@frontainer
  19. 19. ©"2014"LIG"INC."@frontainer
  20. 20. Dirty&Checking そこの値を変えなければ良いということではなく、watch対象の 値は変更されていないことをチェックされる src/ng/rootScope.js.7262836 Object.observeの普及はいつになることやら ©"2014"LIG"INC."@frontainer
  21. 21. まとめ • 双方向バインディングが必要でない場合は適切にOne%&me( Bindingしていく • Watch数をパフォーマンスチェック指標のひとつに 今回はChrome拡張の「Angular-watchers」を使って確認しました ©"2014"LIG"INC."@frontainer
  22. 22. ご静聴ありがとうございました 本日のサンプルはこちら h"ps://github.com/frontainer/ligblog6sample スライドはこちら h"p://www.slideshare.net/frontainer ©"2014"LIG"INC."@frontainer

×