Top Banner
アメーバ事業本部 フロントエンドディベロッパー 五藤 佑典 Componentization with Gilgamesh - Frontrend Conference Final 2015.02.21 -
61

Componentization with Gilgamesh

Jul 18, 2015

Download

Technology

Yusuke Goto
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Componentization with Gilgamesh

アメーバ事業本部フロントエンドディベロッパー 五藤 佑典

Componentizationwith Gilgamesh- Frontrend Conference Final 2015.02.21 -

Page 2: Componentization with Gilgamesh

  @ygoto3_ ygoto3.com!

Page 3: Componentization with Gilgamesh

UIコンポーネント

Page 4: Componentization with Gilgamesh

最近は選択肢が多いです。(迷います)

Page 5: Componentization with Gilgamesh

コンポーネントを揃えて

UIのコードを綺麗にしたい

Page 6: Componentization with Gilgamesh

angular.module(‘demo’).directive( ‘postForm’, function () { return { restrict: ‘E’, templateUrl: ‘./template.html’, link: function () {} }; });

Page 7: Componentization with Gilgamesh

<post-form />

stockimages / FreeDigitalPhotos.net

Page 8: Componentization with Gilgamesh

<body>" <global-header />" <key-visual />"

<post-form />"</body>

Page 9: Componentization with Gilgamesh
Page 10: Componentization with Gilgamesh

理想

Page 11: Componentization with Gilgamesh

でも現実は…

Page 12: Componentization with Gilgamesh

このページだけラベル変えたい。

👤

Page 13: Componentization with Gilgamesh

👍

Page 14: Componentization with Gilgamesh

<post-form"

label=“まずは試してみる”/>

Page 15: Componentization with Gilgamesh

これ、このタイミングは、 あんまり主張してほしくないなー

👤

Page 16: Componentization with Gilgamesh

👍

Page 17: Componentization with Gilgamesh

<post-form"

label=“最初の投稿” size=“small”"

/>

Page 18: Componentization with Gilgamesh

数字が下がってる。明日イベント打ちたい! あそこで使ってるアレ、アレと同じで 大丈夫なんで、ちょっとテイスト変えて 明日までにお願いしますー

👤

Page 19: Componentization with Gilgamesh

👍

Page 20: Componentization with Gilgamesh

<post-form"

label=“最初の投稿” size=“small”"

skin=“dark”"

/>

Page 21: Componentization with Gilgamesh

………………………………… …………………… ……………………………

👤

Page 22: Componentization with Gilgamesh

👍

Page 23: Componentization with Gilgamesh

<post-form"

label=“最初の投稿” size=“small”"

skin=“dark”"

is-followed=“true”"

stars=“12”"

limit=“1000”"

…"

…"

/>

Page 24: Componentization with Gilgamesh

stockimages / FreeDigitalPhotos.net

Page 25: Componentization with Gilgamesh

最初は綺麗だった…

Page 26: Componentization with Gilgamesh

汎用性は必要

Page 27: Componentization with Gilgamesh

どこまで必要かは

予測が難しい

Page 28: Componentization with Gilgamesh

Gilgamesh to the Rescue

Page 29: Componentization with Gilgamesh

Gilgamesh to the Rescue

https://github.com/sskyy/Gilgamesh

Page 30: Componentization with Gilgamesh

Gilgamesh

JavaScript フレームワークを拡張するライブラリ集

• テンプレート拡張ライブラリ • データソースライブラリ • もっと増える?

Page 31: Componentization with Gilgamesh

Gilgamesh

JavaScript フレームワークを拡張するライブラリ集

• テンプレート拡張ライブラリ • データソースライブラリ • もっと増える?

Page 32: Componentization with Gilgamesh

予期できなかった必要な汎用性を

復活してくれるライブラリ

Page 33: Componentization with Gilgamesh

サポート対象

サポート済 サポート予定 サポート予定

Page 34: Componentization with Gilgamesh

Gilgamesh でコンポーネント作成(w/ Angular)

Page 35: Componentization with Gilgamesh

directive component

Page 36: Componentization with Gilgamesh

angular.module(‘demo’).directive( ‘postForm’, function () { return { templateUrl: ‘./template.html’, link: function () {} }; });

Page 37: Componentization with Gilgamesh

angular.module(‘demo’).directive( ‘postForm’, function () { return { templateUrl: ‘./template.html’, link: function () {} }; });

Page 38: Componentization with Gilgamesh

angular.module(‘demo’).component( ‘postForm’, function () { return { templateUrl: ‘./template.html’, link: function () {} }; });

Page 39: Componentization with Gilgamesh

<div post-form></div>

Page 40: Componentization with Gilgamesh

<div class="well">"

<form class="form-horizontal">"

<fieldset class="">"

<legend>Post Form Component</legend>"

<div class="form-group">"

<label for="user" class="control-label col-xs-2">名前:</label>"

<div class="col-xs-10">"

<input type="text" class="form-control" ng-model="user.name" placeholder="名前" />"

</div>"

</div>"

<div class="form-group">"

<label for="E-mail" class="control-label col-xs-2">Eメール:</label>"

<div class="col-xs-10">"

<input type="text" class="form-control" ng-model="user.email" placeholder="Eメール" />"

<div class="checkbox">"

<label><input type="checkbox">購読する</label>"

</div>"

</div>"

</div>"

<div class="form-group">"

<div class="col-xs-offset-2 col-xs-2">"

<button class="btn btn-primary btn-block" ng-click="user.save()" gm-role="save">登録</button>"

</div>"

<div class="col-xs-2">"

<button class="btn btn-block" ng-click="user.cancel()" gm-role="cancel">中止</button>"

</div>"

</div>"

</fieldset>"

</form>"

</div>"

<div post-form></div>

template.html

Page 41: Componentization with Gilgamesh

ラベルと色が弱いな。。 ここだけはボタンを強調したい!

👤

Page 42: Componentization with Gilgamesh

<div class="well">"

<form class="form-horizontal">"

<fieldset class="">"

<legend>Post Form Component</legend>"

<div class="form-group">"

<label for="user" class="control-label col-xs-2">名前:</label>"

<div class="col-xs-10">"

<input type="text" class="form-control" ng-model="user.name" placeholder="名前" />"

</div>"

</div>"

<div class="form-group">"

<label for="E-mail" class="control-label col-xs-2">Eメール:</label>"

<div class="col-xs-10">"

<input type="text" class="form-control" ng-model="user.email" placeholder="Eメール" />"

<div class="checkbox">"

<label><input type="checkbox">購読する</label>"

</div>"

</div>"

</div>"

<div class="form-group">"

<div class="col-xs-offset-2 col-xs-2">"

<button class="btn btn-primary btn-block" ng-click="user.save()" gm-role="save">登録</button>"

</div>"

<div class="col-xs-2">"

<button class="btn btn-block" ng-click="user.cancel()" gm-role="cancel">中止</button>"

</div>"

</div>"

</fieldset>"

</form>"

</div>"

<div post-form></div>

template.html

Page 43: Componentization with Gilgamesh

<div class="well">"

<form class="form-horizontal">"

<fieldset class="">"

<legend>Post Form Component</legend>"

<div class="form-group">"

<label for="user" class="control-label col-xs-2">名前:</label>"

<div class="col-xs-10">"

<input type="text" class="form-control" ng-model="user.name" placeholder="名前" />"

</div>"

</div>"

<div class="form-group">"

<label for="E-mail" class="control-label col-xs-2">Eメール:</label>"

<div class="col-xs-10">"

<input type="text" class="form-control" ng-model="user.email" placeholder="Eメール" />"

<div class="checkbox">"

<label><input type="checkbox">購読する</label>"

</div>"

</div>"

</div>"

<div class="form-group">"

<div class="col-xs-offset-2 col-xs-2">"

<button class="btn btn-primary btn-block" ng-click="user.save()" gm-role="save">登録</button>"

</div>"

<div class="col-xs-2">"

<button class="btn btn-block" ng-click="user.cancel()" gm-role="cancel">中止</button>"

</div>"

</div>"

</fieldset>"

</form>"

</div>"

<div post-form></div>

template.html

<div class="col-xs-2">"

<button class="btn btn-block" ng-click=“user.cancel()""

gm-role="cancel">中止</button>"

</div>

Page 44: Componentization with Gilgamesh

<div class="well">"

<form class="form-horizontal">"

<fieldset class="">"

<legend>Post Form Component</legend>"

<div class="form-group">"

<label for="user" class="control-label col-xs-2">名前:</label>"

<div class="col-xs-10">"

<input type="text" class="form-control" ng-model="user.name" placeholder="名前" />"

</div>"

</div>"

<div class="form-group">"

<label for="E-mail" class="control-label col-xs-2">Eメール:</label>"

<div class="col-xs-10">"

<input type="text" class="form-control" ng-model="user.email" placeholder="Eメール" />"

<div class="checkbox">"

<label><input type="checkbox">購読する</label>"

</div>"

</div>"

</div>"

<div class="form-group">"

<div class="col-xs-offset-2 col-xs-2">"

<button class="btn btn-primary btn-block" ng-click="user.save()" gm-role="save">登録</button>"

</div>"

<div class="col-xs-2">"

<button class="btn btn-block" ng-click="user.cancel()" gm-role="cancel">中止</button>"

</div>"

</div>"

</fieldset>"

</form>"

</div>"

<div post-form></div>

template.html

<div class="col-xs-2">"

<button class="btn btn-block" ng-click=“user.cancel()""

gm-role="cancel">中止</button>"

</div>

Page 45: Componentization with Gilgamesh

<div post-form></div>

Page 46: Componentization with Gilgamesh

<div post-form gm-tpl-partial>"

<button class="btn btn-danger btn-block" ng-click=“user.cancel()""

gm-role="cancel">解除</button>"

</div>

Page 47: Componentization with Gilgamesh

<div post-form gm-tpl-partial>"

<button class="btn btn-danger btn-block" ng-click=“user.cancel()""

gm-role="cancel">解除</button>"

</div>

Page 48: Componentization with Gilgamesh

ここはユーザーにできるだけ登録させたい。 中止ボタンは見せたくない。

👤

Page 49: Componentization with Gilgamesh

<div class="well">"

<form class="form-horizontal">"

<fieldset class="">"

<legend>Post Form Component</legend>"

<div class="form-group">"

<label for="user" class="control-label col-xs-2">名前:</label>"

<div class="col-xs-10">"

<input type="text" class="form-control" ng-model="user.name" placeholder="名前" />"

</div>"

</div>"

<div class="form-group">"

<label for="E-mail" class="control-label col-xs-2">Eメール:</label>"

<div class="col-xs-10">"

<input type="text" class="form-control" ng-model="user.email" placeholder="Eメール" />"

<div class="checkbox">"

<label><input type="checkbox">購読する</label>"

</div>"

</div>"

</div>"

<div class="form-group">"

<div class="col-xs-offset-2 col-xs-2">"

<button class="btn btn-primary btn-block" ng-click="user.save()" gm-role="save">登録</button>"

</div>"

<div class="col-xs-2">"

<button class="btn btn-block" ng-click="user.cancel()" gm-role="cancel">中止</button>"

</div>"

</div>"

</fieldset>"

</form>"

</div>"

<post-form />

template.html

<div class="col-xs-2">"

<button class="btn btn-block" ng-click=“user.cancel()""

gm-role="cancel">中止</button>"

</div>

Page 50: Componentization with Gilgamesh

<div post-form></div>

Page 51: Componentization with Gilgamesh

<div post-form gm-tpl-exclude=“cancel”></div>

Page 52: Componentization with Gilgamesh

思いきって中止ボタンをコンポーネントの 外に出して差別化して目立たせたい。

👤

Page 53: Componentization with Gilgamesh

<button class=“btn btn-danger btn-block”"

gm-import=“postForm”>"

<div post-form id=“postForm”></div>

通常の DOM 構造では Scope 外となる

場所にもボタンを配置できる

Page 54: Componentization with Gilgamesh

通常の DOM 構造では Scope 外となる

場所にもボタンを配置できる

<button class=“btn btn-danger btn-block”"

gm-import=“postForm”"

ng-click=“cancel()”>"

<div post-form id=“postForm”></div>

import 元コンポーネントの scope を参照できる。

Page 55: Componentization with Gilgamesh

コンポーネントの拡張

Page 56: Componentization with Gilgamesh

angular.module(‘demo’).component( ‘postFormSubscribe’, function () { return { extend: ‘postForm’, templateUrl: ‘./template.html’, link: function (iScope) { iScope.user.subscription = true; } }; });

Page 57: Componentization with Gilgamesh

<div post-form-subscribe></div>

postForm の link で設定された 機能も継承されている。

Page 58: Componentization with Gilgamesh

そのほかにも機能が多々

Page 59: Componentization with Gilgamesh

触ってみて• コンポーネントの再利用性を後から高めるための便利な機能が追加できる

• ドキュメントの不備が多い

• バグにいっぱいあたる

• パフォーマンス?

• プロダクトではまだ使えないけど…

コンポーネント・ベース開発の ヒントも多いのでゆるく追ってみたい

Page 60: Componentization with Gilgamesh

Reference• Gilgameshhttp://sskyy.github.io/Gilgamesh/

• Gilgamesh: bring Angular to the next levelhttp://www.reddit.com/r/programming/comments/2s5exu/gilgamesh_bring_angular_to_the_next_level/

• Bootswatch: Free themes for Bootstrap http://bootswatch.com/

• ECOSAVE BOOTSTRAP ENVIRONMENT TEMPLATEhttp://www.binarytheme.com/ecosave-bootstrap-environment-template/

Page 61: Componentization with Gilgamesh

ありがとうございました