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
ES7 Decorators
Search
OKUNOKENTARO
September 29, 2015
Programming
3
3.3k
ES7 Decorators
第60回HTML5とか勉強会 - ECMAScript 2015 & 2016での発表に使用した資料です
OKUNOKENTARO
September 29, 2015
Tweet
Share
More Decks by OKUNOKENTARO
See All by OKUNOKENTARO
トレタO/X アーキテクチャ移行記 Next.js App Router化への道のり / TORETA TECH UPDATE 1
okunokentaro
5
9.6k
Podcastを継続する技術 / refactoradio-240119
okunokentaro
1
160
Webアプリケーション設計の第一歩は ディレクトリの整理から / Encraft 1
okunokentaro
34
9.9k
JSONとJSON Schemaを改めて理解する / tokyo_study
okunokentaro
9
2.2k
それでもどうしてRecoilを使うのか / Harajuku.ts Meetup Recoil
okunokentaro
19
5.4k
TypeScriptは10年でこんなに進化しました / TechFeed Experts Night 11
okunokentaro
6
1.7k
Hasura.io RDBをサクサク作る方法はARやO/RMだけじゃなくなりました/hasura-io
okunokentaro
5
620
コードには型アノテーションよりも要件アノテーションを増やせ!/harajukuts2
okunokentaro
14
6.2k
10年と3ヶ月でWebサービスを作った話 / Piyogrammer Conference 2021
okunokentaro
2
1k
Other Decks in Programming
See All in Programming
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
930
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Jakarta EE meets AI
ivargrimstad
0
650
Better Code Design in PHP
afilina
PRO
0
130
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
CSC509 Lecture 12
javiergs
PRO
0
160
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
初めてDefinitelyTypedにPRを出した話
syumai
0
420
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
The Language of Interfaces
destraynor
154
24k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
A better future with KSS
kneath
238
17k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
BBQ
matthewcrist
85
9.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Adopting Sorbet at Scale
ufuk
73
9.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Building Applications with DynamoDB
mza
90
6.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Transcript
ES7 Decorators @armorik83 Sep 29, 2015 ୈ60ճHTML5ͱ͔ษڧձ
• @armorik83ɾ • -ɾ • ژࢢग़A • AngularϢʔβάϧʔϓ ng-kyotoද Hello
AngularJSΞϯνύλʔϯूɺDestructuring assignmentͷ͝ར༻ܭըతʹɺͳͲ
Decorators Syntax
• ECMAScriptͱʢׂѪʣ • Babelͷදهʹ฿ͬͯES2015, ES7Ͱ౷Ұ͠·͢ ES7
Decoratorsͱ? class Person { @nonenumerable get kidCount() { return this.children.length;
} } function nonenumerable(target, name, descriptor) { descriptor.enumerable = false; return descriptor; } https://github.com/wycats/javascript-decorators#detailed-design
DecoratorsԿΛ͢Δ? • ES2015 ClassϓϩύςΟʹରͯ͠ɺDecoratorsߏจʹ Αͬͯ০ɺऍͰ͖Δ • ԼͷClassϓϩύςΟɺϝιουʹ༗ޮ
JSʹ͓͚ΔDecoratorsͷىݯ • 20144݄ɺECMAϛʔςΟϯά TC39 ʹͯwycatsࢯ͔Β ఏग़͞Εͨϓϩϙʔβϧ • 201410݄ɺϓϩϙʔβϧΛ͔ͬͯΒ͔ͣAngular։ൃ νʔϜ͕"AtScript"ͳΔಠࣗߏจΛൃදʢDart༝དྷͬΆ͍ʣ •
20153݄ɺAngularνʔϜͱMicrosoft͕ࣾڠྗ͢Δ͜ͱΛ ද໌ɺTypeScript 1.5ʹ༷ͯͱͯ͠࠾༻
ES7 Decorators • 20159݄ݱࡏɺECMA262 Proposals Stage 1 • ෳͷProposalsʹؔ༩͍ͯ͠ΔYehuda Katz
(wycats) ࢯͱɺ MicrosoftࣾͷJonathan Turnerࢯ͕ࡦఆͷத৺ͱͳ͍ͬͯΔ • BabelͰར༻Մ
TypeScript Decorators • 20159݄ݱࡏɺTypeScript 1.6.2Ͱར༻Մ • ҆ఆ൛ʹؚ·Ε͓ͯΓʢ͓ͦΒ͘෦తʹʣ༷͋Δ͕ɺ ༷ॻʹهࡌ͞Ε͍ͯͳ͍ • ໌֬ͳ༷ɺECMAଆͷࡦఆʹ߹ΘͤΑ͏ͱ͍ͯ͠Δͱਪଌ
• BabelଆECMA Proposalsʹݫີʹ४ڌ͍ͯ͠ΔͨΊɺඍົ ʹTypeScriptଆͷڍಈͱ͕ࠩ͋Δ • ྫ͑TypeScriptͷΈҾʹରͯ͠ద༻Ͱ͖Δ
͍ํ • Babel • babel --optional es7.decorators • TypeScript •
tsc --experimentalDecorators • ·ͩ྆ํͱ࣮ݧஈ֊ѻ͍ͰΦϓγϣϯ͕ඞཁ
ଞݴޠͰͷDecorators • C#ͷMetadataߏจʹىݯ͕͋ΔΑ͏Ͱɺ2001͔Β֬ೝ ͞Ε͍ͯΔ֓೦ • @Ͱॻ͖࢝ΊΔݴޠJava, PythonͳͲ • ࠓճɺJavaScript͕Կ͔ੜΈग़ͨ͠༁Ͱͳ͘ɺଞݴޠ͔Β ࠾ΓೖΕ͍ͯΔ
• [Qiita JavaScript Decorators] [ݕࡧ]
༻్
Angular 2 • ϑϨʔϜϫʔΫ"AngularJS"ͷ࣍ظϝδϟʔόʔδϣϯ • APIAngularJS 1ܥ͔Βେ෯ʹมߋ • ৽APIͰવͷΑ͏ʹDecoratorsߏจ͕Έࠐ·Ε͍ͯΔ •
Microsoftࣾ TypeScript։ൃνʔϜͱ࿈ܞ͍ͯ͠Δ • Decoratorsߏจ͕ʢଟগͷमਖ਼͋ΕͲʣഇҊʹͳΔ͜ͱ ແ͍ͱΈ͍ͯΔ
Angular 2 • TypeScriptͰ͔͠༻Ͱ͖ͳ͍Decoratorsߏจͷ͍ํ ͭ·ΓBabelͰΤϥʔͱͳΔ͍ํɺAngular 2ઐ༻ͱ ࢥ͓͍͍͍ͬͯͯ. • DecoratorsߏจΛ༻͍ͯԿ͔ࣗ࡞͢Δࡍɺ͜ͷ͍ํ ECMAతʹকདྷ͕ଋ͞Ε͍ͯͳ͍
class MyComponent { constructor(@Attribute('title') title: string) { // } }
Redux • ReduxͰreact-redux bindingʹ͓͍ͯɺDecoratorsߏจʹ ΑΔ؆қͳه๏༻ҙ͞Ε͍ͯΔ • ͔ͤͬ͘ͳͷͰ͔ͬͬͯΈΔ͔ʁ • ڧ੍Ͱͳ͍ͷͰɺΘͳͯ͘Α͍ @connect(mapStateToProps)
export default class CounterContainer { // }
core-decorators.js • https://github.com/jayphelps/core-decorators.js ɾ • DecoratorsߏจΛϑϧ׆༻ͨ͠ϥΠϒϥϦू • @readonly, @override, @deprecate,
@debounceͳͲ 10छྨ͕༻ҙ͞Ε͍ͯΔ • ͜ͷOSSɺଞݴޠͰͷDecoratorsߏจͷΘΕํͳͲ ࢀߟʹ͢Δͱࣗ࡞͘͢͠ͳΔͣ
࡞ͬͯΈͨ
wrasse CC0 Roban Kramer / Bluehead Wrasse
wrasse • https://github.com/chatwork/wrasse ɾ • npm i -S wrasse ɾ
• ChatWorkࣾॳͷnpm OSSͱͳΓ·ͨ͠ • ࣾίʔυωʔϜʹڕͷͷ͕͋ͬͨͨΊɺؔ࿈ͤ͞Α͏ • ຊޠͰϕϥɺभͰΫαϏͱݺΕΔڕ • ϫοηʔͱ͔ϥοηʔͱ͔ϫογϣΠͱ͔͖ʹݺ͍͍
wrasseԿΛ͢Δͷ? • ΫαϏ͚ͩ͋ͬͯɺDependency InjectionϥΠϒϥϦͰ͢ • AngularJSͰͷDIܦݧɺNode.js, ES2015 moduleϕʔεʹ ͓͚ΔϞοΫςετΛͲ͏ߦ͏͔ʹ͍ͭͯߟ͑ͨͷػߏ @wr.inject({
ComponentA, ComponentB, ComponentC }) export default class Application { // }
ͨͿΜ࣌ؒແ͍͚Ͳ ͍ํ
͍ํ 1/5 • WrasseΠϯελϯεΛੜ͢Δ import Wrasse from 'wrasse'; const wr
= new Wrasse(); export default wr;
• ੜͨ͠WrasseΠϯελϯεΛimportͯ͠ϞδϡʔϧΛొ JNQPSUXSGSPNXSBTTFTJOHMFUPO8SBTTF؎ٝأةٝأ JNQPSU@$PNQPOFOU"GSPNDPNQPOFOUB㹋⡤JNQPSU JNQPSU@$PNQPOFOU#GSPNDPNQPOFOUC JNQPSU\ $PNQPOFOU" $PNQPOFOU# ^GSPNNPEVMFLFZT㹋⡤ㄎן⳿ׅךؗ٦JNQPSU
XSTFU $PNQPOFOU" @$PNQPOFOU" ؗ٦ה㹋⡤秡➰ֽג涫ꐮ XSTFU $PNQPOFOU# @$PNQPOFOU# FYQPSUEFGBVMUXS ͍ํ 2/5
• ొͨ͠ϞδϡʔϧΛݺͿͨΊͷΩʔΛએݴ 㛙暕ח׃ֽל4ZNCPM崞欽 FYQPSUDPOTU$PNQPOFOU"4ZNCPM $PNQPOFOU" FYQPSUDPOTU$PNQPOFOU#4ZNCPM $PNQPOFOU# 4ZNCPMָ䱰欽׃חְֻ㜥さכ俑㶵ד圓זְ
FYQPSUDPOTU$PNQPOFOU$$PNQPOFOU$ FYQPSUDPOTU$PNQPOFOU%$PNQPOFOU% ͍ํ 3/5
• ࣮ͰXSJOKFDU Ͱએݴ͢ΔͱɺUIJT͔ΒऔಘͰ͖Δ JNQPSUXSGSPNSFHJTUFSEFQFOEFODJFT JNQPSU\ $PNQPOFOU" $PNQPOFOU# ^GSPNNPEVMFLFZT !XSJOKFDU
\ֿֿח%FDPSBUPST圓俑 $PNQPOFOU" ؗ٦&4䕎䒭ך0CKFDUד♷ִ\BB CC^\B C^ה剅ֽװא $PNQPOFOU# ^ FYQPSUEFGBVMUDMBTT"QQMJDBUJPO\ DPOTUSVDUPS \ DPOTPMFMPH UIJT$PNQPOFOU" 呓秛幥 ^ ^ ͍ํ 4/5
• ςετͰCFGPSF&BDIͳͲͰ湫䱸4FU EFTDSJCF *OKFDUNPDL \ CFGPSF&BDI \ ٌحؙ䊴׃剏ִ "QQMJDBUJPOQSPUPUZQF$PNQPOFOU#.PDL$PNQPOFOU#
^ JU TIPVMECFJOKFDUFE.PDL$PNQPOFOU$ \ DPOTUBQQOFX"QQMJDBUJPO BQQ$PNQPOFOU$.PDL$PNQPOFOU$JUⰻד〳 ^ ^ ͍ํ 5/5
Կʹ͏͔ • ͷϩδοΫΛ࣋ͨͳ͍Singleton ControllerͷΑ͏ͳՕॴ ͷϞοΫςετରࡦ • ࣾҊ݅ͰطʹwrasseΛ࠾༻͍ͯ͠Δ ʢਅ૬ٯͰɺۀίʔυ͔ΒDIػߏͷΈநग़ͨ͠ʣ • ࣾҊ݅Ͱ࠾༻ͱ͍͏͜ͱɺBabel
--optional༻த • @kyo_agoŰƅŘŤƃͷԼͰɺׂͱ͖উखΒͤͯΒͬͯ·͢
·ͱΊ
·ͱΊ • DecoratorsߏจStage 1͚ͩͲTypeScriptਞӦਐΊ͍ͯΔ ෆࢥٞͳཱͪҐஔͷϓϩϙʔβϧ • Angular 2͕ຊ֨తʹ࠾༻ͪ͠ΌͬͨͨΊɺͨͿΜੜ͖Δ • ES7ͬΆ͞ΛઌऔΓ͢ΔͳΒDecoratorsͬͯΈ·ͤΜ͔
એ • AngularϢʔβάϧʔϓ ng-kyoto ͷୈࡾճͱͳΔMeetup͕ ։࠵ܾఆ • ng-kyoto Angular Meetup
#3 ɾ • 201511݄22ʢʣ • ։࠵બఆதɺ͓ͦΒ͘ژࢢ • ਖ਼ࣜͳࠂɺืू։࢝10݄தΛ༧ఆ • ΈΜͳདྷͯͶ
Thank you for listening! Sep 29, 2015 ୈ60ճHTML5ͱ͔ษڧձ @armorik83