SlideShare a Scribd company logo
1 of 16
Download to read offline
ガス単独診断に学ぶ
VueJS
2017/11/28
Tomoya Kawanishi
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
1自己紹介
川西 智也
エネチェンジ株式会社 チーフエンジニア
Ruby関西代表
出自
新卒で入社したのは、関西電力
もともとはサーバサイド、インフラまわりを主に担当
最近はフロントエンドも開発するようになった
Buzzった記事
Ruby のオススメの機能 7選
https://qiita.com/cuzic/items/a265f140fdff289d5c07
PostgreSQL のパフォーマンスチューニング
https://qiita.com/cuzic/items/f9b846e6171a54079d77
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
ガス単独診断とは
従来、電気・ガスの組合せで最適な会社を提案
電気はすでに切替済のユーザも多い
ガスだけの組合せでの節約額の提示のニーズあり
ガス単独診断をリリース!
初期版はチャットUIだった
ただし、分岐もなく一直線で聞きたいことを聞くだけ
チャットUIの意味なし
VueJS を使った SPA に全面リニューアル!
ユーザ利便性を向上!
2
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
ガス単独診断(リニューアル後) 3
https://enechange.jp/gas
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
computed プロパティを多用!
computed プロパティはかなり便利!
たとえ、1行の内容でも computed プロパティにする
読みやすく簡潔になる
結果がキャッシュされるので、高速化の効果もある
4
computed: {
postcodeFull(){
return this.postcode1 + this.postcode2;
},
isPostcodeValid(){
return this.postcodeFull.match(/^¥d{7}$/);
},
isPostcodeErrorVisible(){
return this.tainted["postcode1"] &&
this.tainted["postcode2"] &&
!this.isPostcodeValid;
},
…
郵便番号のエラー表示での使用例
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
compted プロパティを watch !
VueJS では computed プロパティを watch できる
条件分岐をシンプルにできる
5
watch: {
isPostcodeValid(current){
if(current){
this.getGasProviders();
this.resetSimulation();
}
},
…
郵便番号入力後の処理での使用例
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
$refs の活用
$refs で、特定の DOM 要素を参照可能
ここでは、郵便番号1を入力後、フォーカスを移動する
ために $refs を使っている
6
watch: {
isPostcode1Valid(current, old){
if(current){
this.$refs.postcode2.focus();
}
},
…
},
computed: {
isPostcode1Valid(){
return this.postcode1.length === 3;
},
<input type="text" … name="postcode2"
v-model="postcode2" … ref="postcode2">
郵便番号での $refs の使用例
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
入力エラーのリアルタイム表示 1 / 2 7
<div … v-show="isPostcodeErrorVisible"><span>
郵便番号を入力してください</span></div>
computed: {
isPostcodeErrorVisible(){
return this.tainted["postcode1"] &&
this.tainted["postcode2"] &&
!this.isPostcodeValid;
},
入力誤りがあったとき、エラー文言を表示したい
最初から、エラー文言が表示されてるとウザい
入力後だけ、
エラー表示を
有効化
tainted という
プロパティに
触ったか
どうかを格納
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
入力エラーのリアルタイム表示 2 / 2
@blur は v-on:blur の syntax sugar
blur イベントをフックして、特定の処理を実行できる
this.$set(this.tainted, fieldname, true); は
this.tainted[fieldname] = true と同じ意味
$set を使うと computed 等の再計算が実行される
8
methods: {
doTaint(event){
if(event.target.value){
const fieldname = event.target.name;
this.$set(this.tainted, fieldname, true);
}
}
…
<input type="text" … name="postcode2" v-model="postcode2" …
@blur="doTaint" ref="postcode2">
エラー表示での @blur イベントの使用例
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
結果は1行ごとに v-component として設計
Vueコンポーネントをどう分割するか?
設計結果
入力: 1つの Vue コンポーネント
結果: 1行(1つのガスプラン)ごとにコンポーネント化
computed プロパティの機能を活用し、
View 側をシンプルに、見通しよく記述
9
<ul class="m__plans-container">
<li v-for="result in results">
<% if is_pc? %>
<plans-finder-item-pc :result="result" />
<% else %>
<plans-finder-item-smp :result="result" />
<% end %>
</li>
</ul>
結果ごとに Vue コンポーネントでレンダリング
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
x-template の活用 10
<script type="text/x-template" id="plans-finder-item-pc">
<%= render 'plans_finder_item_pc' %>
</script>
<script type="text/x-template" id="plans-finder-item-smp">
<%= render 'plans_finder_item_smp' %>
</script>
結果画面のマークアップをどう記述するか?
x-template を使って、そのまま従来の View を活用
.vue などは逆に活用せず
Ruby on Rails の従来の View と同じ運用の方が、
トータルで分かりやすいと判断した
従来の Rails プロジェクトで開発していた人にとっての
とっつきやすさを重視
x-template の活用の例
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
Spread演算子を使った共通化
ES2015 の Spread 演算子を使って、オブジェクトリテ
ラルの一部を共通的に利用
相違点は、ID だけ。
すっきり!
11
const plansFinderItemPc = {
template: "#plans-finder-item-pc",
...plansFinderItemCommon
};
const plansFinderItemSmp = {
template: "#plans-finder-item-smp",
...plansFinderItemCommon
};
Vue.component('plans-finder-item-pc', plansFinderItemPc);
Vue.component('plans-finder-item-smp', plansFinderItemSmp);
モバイルと PC で、共通の設定を利用する例
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
Filter の活用
一部の処理は View 側で頻出する(例: カンマ区切り)
メソッド呼び出しは、読みにくい
右から左に進むと思考が止まる
Filter を活用!
左から右に進む!読みやすい!
12
filters: {
numberWithDelimiter(value){
return value.toString().replace(/¥B(?=(¥d{3})+(?!¥d))/g, ",");
},
abs(value){
return Math.abs(Number(value));
}
<span class="value">{{ actualYearSaving | abs |
numberWithDelimiter }}</span><span class="unit">円</span><span v-
if="isCheaper">節約</span> <span v-else>割高</span>
Filter の活用例
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
番外編 lodash の活用
Lodash はすごく便利だった。オススメ
_.debounce
_.differenceBy
_.each
_.find
_.filter
_.isEmpty
_.map
_.reject
_.some
_.sortBy
13
Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」
14ガス単独診断全面リニューアルの感想
VueJS を活用して、全面リニューアルを実施した
2週間で全面リニューアルが完了でき、
VueJS の開発生産性の高さを実感した
特に computed プロパティが非常に便利だった
View 側のコードをシンプルにできた
15
ご清聴ありがとう
ございました

More Related Content

What's hot

Openstackサテライトプロジェクトまとめ
OpenstackサテライトプロジェクトまとめOpenstackサテライトプロジェクトまとめ
OpenstackサテライトプロジェクトまとめTakahiro Shida
 
20131116_OSC福岡_CloudOS「Apache CloudStack」概要
20131116_OSC福岡_CloudOS「Apache CloudStack」概要20131116_OSC福岡_CloudOS「Apache CloudStack」概要
20131116_OSC福岡_CloudOS「Apache CloudStack」概要Midori Oge
 
20130914_OSC北海道_CloudStack一問一答!
20130914_OSC北海道_CloudStack一問一答!20130914_OSC北海道_CloudStack一問一答!
20130914_OSC北海道_CloudStack一問一答!Midori Oge
 
ApacheCloudstack4.1最新情報ver2
ApacheCloudstack4.1最新情報ver2ApacheCloudstack4.1最新情報ver2
ApacheCloudstack4.1最新情報ver2Midori Oge
 
Open Source Study Session #3
Open Source Study Session #3Open Source Study Session #3
Open Source Study Session #3Satoshi Konno
 
Physical Web導入の話
Physical Web導入の話Physical Web導入の話
Physical Web導入の話KatsuyaENDOH
 
Riot.jsを用いたweb開発 takusuta tech conf #1
Riot.jsを用いたweb開発   takusuta tech conf #1Riot.jsを用いたweb開発   takusuta tech conf #1
Riot.jsを用いたweb開発 takusuta tech conf #1Keisuke Imai
 
Azure Kubernetes Service の「学び方」
Azure Kubernetes Service の「学び方」Azure Kubernetes Service の「学び方」
Azure Kubernetes Service の「学び方」Lisa Imai
 
Node.jsとAWS入門(Elastic Beanstalk & AWS SDK for Node.js)
Node.jsとAWS入門(Elastic Beanstalk & AWS SDK for Node.js)Node.jsとAWS入門(Elastic Beanstalk & AWS SDK for Node.js)
Node.jsとAWS入門(Elastic Beanstalk & AWS SDK for Node.js)崇之 清水
 
20201216 jazug azureexam
20201216 jazug azureexam20201216 jazug azureexam
20201216 jazug azureexamTomoakiOno
 
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LTAzure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LTJun-ichi Sakamoto
 
Introduction to WildFly Swarm
Introduction to WildFly SwarmIntroduction to WildFly Swarm
Introduction to WildFly SwarmYoshimasa Tanabe
 
日本仮想化技術 OpenStackサービスメニューのご紹介
日本仮想化技術 OpenStackサービスメニューのご紹介日本仮想化技術 OpenStackサービスメニューのご紹介
日本仮想化技術 OpenStackサービスメニューのご紹介VirtualTech Japan Inc.
 
20140726 jaws-ug chiba AWS operation best practice
20140726 jaws-ug chiba AWS operation best practice20140726 jaws-ug chiba AWS operation best practice
20140726 jaws-ug chiba AWS operation best practiceKazuki Ueki
 
How to face the Kubernetes ?
How to face the Kubernetes ? How to face the Kubernetes ?
How to face the Kubernetes ? Yoshio Terada
 
AWSを用いてNode-REDでらくらくAPI
AWSを用いてNode-REDでらくらくAPIAWSを用いてNode-REDでらくらくAPI
AWSを用いてNode-REDでらくらくAPIKazumi Kanda
 
Ansible の CI を drone/Dokcker で試してみた
Ansible の CI を drone/Dokcker で試してみたAnsible の CI を drone/Dokcker で試してみた
Ansible の CI を drone/Dokcker で試してみたKenta Nishimura
 
最近Preview公開されたAzure テストサービスを試してみた
最近Preview公開されたAzure テストサービスを試してみた最近Preview公開されたAzure テストサービスを試してみた
最近Preview公開されたAzure テストサービスを試してみたHiroyuki Mori
 
OpenStack最新動向 2016/2
OpenStack最新動向 2016/2OpenStack最新動向 2016/2
OpenStack最新動向 2016/2Akira Yoshiyama
 
Invitation to the Open Cloud Campus #osckansai 2011
Invitation to the Open Cloud Campus #osckansai 2011Invitation to the Open Cloud Campus #osckansai 2011
Invitation to the Open Cloud Campus #osckansai 2011Masahito Zembutsu
 

What's hot (20)

Openstackサテライトプロジェクトまとめ
OpenstackサテライトプロジェクトまとめOpenstackサテライトプロジェクトまとめ
Openstackサテライトプロジェクトまとめ
 
20131116_OSC福岡_CloudOS「Apache CloudStack」概要
20131116_OSC福岡_CloudOS「Apache CloudStack」概要20131116_OSC福岡_CloudOS「Apache CloudStack」概要
20131116_OSC福岡_CloudOS「Apache CloudStack」概要
 
20130914_OSC北海道_CloudStack一問一答!
20130914_OSC北海道_CloudStack一問一答!20130914_OSC北海道_CloudStack一問一答!
20130914_OSC北海道_CloudStack一問一答!
 
ApacheCloudstack4.1最新情報ver2
ApacheCloudstack4.1最新情報ver2ApacheCloudstack4.1最新情報ver2
ApacheCloudstack4.1最新情報ver2
 
Open Source Study Session #3
Open Source Study Session #3Open Source Study Session #3
Open Source Study Session #3
 
Physical Web導入の話
Physical Web導入の話Physical Web導入の話
Physical Web導入の話
 
Riot.jsを用いたweb開発 takusuta tech conf #1
Riot.jsを用いたweb開発   takusuta tech conf #1Riot.jsを用いたweb開発   takusuta tech conf #1
Riot.jsを用いたweb開発 takusuta tech conf #1
 
Azure Kubernetes Service の「学び方」
Azure Kubernetes Service の「学び方」Azure Kubernetes Service の「学び方」
Azure Kubernetes Service の「学び方」
 
Node.jsとAWS入門(Elastic Beanstalk & AWS SDK for Node.js)
Node.jsとAWS入門(Elastic Beanstalk & AWS SDK for Node.js)Node.jsとAWS入門(Elastic Beanstalk & AWS SDK for Node.js)
Node.jsとAWS入門(Elastic Beanstalk & AWS SDK for Node.js)
 
20201216 jazug azureexam
20201216 jazug azureexam20201216 jazug azureexam
20201216 jazug azureexam
 
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LTAzure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT
Azure Application Insights + Angular5+ - Global azure boot camp 2019@sapporo LT
 
Introduction to WildFly Swarm
Introduction to WildFly SwarmIntroduction to WildFly Swarm
Introduction to WildFly Swarm
 
日本仮想化技術 OpenStackサービスメニューのご紹介
日本仮想化技術 OpenStackサービスメニューのご紹介日本仮想化技術 OpenStackサービスメニューのご紹介
日本仮想化技術 OpenStackサービスメニューのご紹介
 
20140726 jaws-ug chiba AWS operation best practice
20140726 jaws-ug chiba AWS operation best practice20140726 jaws-ug chiba AWS operation best practice
20140726 jaws-ug chiba AWS operation best practice
 
How to face the Kubernetes ?
How to face the Kubernetes ? How to face the Kubernetes ?
How to face the Kubernetes ?
 
AWSを用いてNode-REDでらくらくAPI
AWSを用いてNode-REDでらくらくAPIAWSを用いてNode-REDでらくらくAPI
AWSを用いてNode-REDでらくらくAPI
 
Ansible の CI を drone/Dokcker で試してみた
Ansible の CI を drone/Dokcker で試してみたAnsible の CI を drone/Dokcker で試してみた
Ansible の CI を drone/Dokcker で試してみた
 
最近Preview公開されたAzure テストサービスを試してみた
最近Preview公開されたAzure テストサービスを試してみた最近Preview公開されたAzure テストサービスを試してみた
最近Preview公開されたAzure テストサービスを試してみた
 
OpenStack最新動向 2016/2
OpenStack最新動向 2016/2OpenStack最新動向 2016/2
OpenStack最新動向 2016/2
 
Invitation to the Open Cloud Campus #osckansai 2011
Invitation to the Open Cloud Campus #osckansai 2011Invitation to the Open Cloud Campus #osckansai 2011
Invitation to the Open Cloud Campus #osckansai 2011
 

More from Tomoya Kawanishi

ENECHANGE社での Scout APM 利用事例
ENECHANGE社での Scout APM 利用事例ENECHANGE社での Scout APM 利用事例
ENECHANGE社での Scout APM 利用事例Tomoya Kawanishi
 
エンジニア転職のノウハウ
エンジニア転職のノウハウエンジニア転職のノウハウ
エンジニア転職のノウハウTomoya Kawanishi
 
Ruby の文字列について
Ruby の文字列についてRuby の文字列について
Ruby の文字列についてTomoya Kawanishi
 
Ruby on Rails のキャッシュ機構について
Ruby on Rails のキャッシュ機構についてRuby on Rails のキャッシュ機構について
Ruby on Rails のキャッシュ機構についてTomoya Kawanishi
 
Ruby初心者からよく質問されること
Ruby初心者からよく質問されることRuby初心者からよく質問されること
Ruby初心者からよく質問されることTomoya Kawanishi
 
RubyGems と Bundler について
RubyGems と Bundler についてRubyGems と Bundler について
RubyGems と Bundler についてTomoya Kawanishi
 
Ruby の正規表現について
Ruby の正規表現についてRuby の正規表現について
Ruby の正規表現についてTomoya Kawanishi
 
Ruby での外部コマンドの実行について
Ruby での外部コマンドの実行についてRuby での外部コマンドの実行について
Ruby での外部コマンドの実行についてTomoya Kawanishi
 
Ruby のワンライナーについて
Ruby のワンライナーについてRuby のワンライナーについて
Ruby のワンライナーについてTomoya Kawanishi
 
AWS のコスト管理をちゃんとしたくてやったこと
AWS のコスト管理をちゃんとしたくてやったことAWS のコスト管理をちゃんとしたくてやったこと
AWS のコスト管理をちゃんとしたくてやったことTomoya Kawanishi
 
PostgreSQL のイケてるテクニック7選
PostgreSQL のイケてるテクニック7選PostgreSQL のイケてるテクニック7選
PostgreSQL のイケてるテクニック7選Tomoya Kawanishi
 
HTTPと Webクローリングについて
HTTPと WebクローリングについてHTTPと Webクローリングについて
HTTPと WebクローリングについてTomoya Kawanishi
 
Active record query interface
Active record query interfaceActive record query interface
Active record query interfaceTomoya Kawanishi
 
Active Support のコア拡張機能について
Active Support のコア拡張機能についてActive Support のコア拡張機能について
Active Support のコア拡張機能についてTomoya Kawanishi
 
Ruby ビジネス創出展 Ruby初心者向けプログラミングセミナー
Ruby ビジネス創出展 Ruby初心者向けプログラミングセミナーRuby ビジネス創出展 Ruby初心者向けプログラミングセミナー
Ruby ビジネス創出展 Ruby初心者向けプログラミングセミナーTomoya Kawanishi
 
RubyのDir、File、IO について
RubyのDir、File、IO についてRubyのDir、File、IO について
RubyのDir、File、IO についてTomoya Kawanishi
 
Thread の利用事例紹介
Thread の利用事例紹介Thread の利用事例紹介
Thread の利用事例紹介Tomoya Kawanishi
 
Ruby の制御構造とリテラルについて
Ruby の制御構造とリテラルについてRuby の制御構造とリテラルについて
Ruby の制御構造とリテラルについてTomoya Kawanishi
 

More from Tomoya Kawanishi (20)

英単語の覚え方
英単語の覚え方英単語の覚え方
英単語の覚え方
 
ENECHANGE社での Scout APM 利用事例
ENECHANGE社での Scout APM 利用事例ENECHANGE社での Scout APM 利用事例
ENECHANGE社での Scout APM 利用事例
 
エンジニア転職のノウハウ
エンジニア転職のノウハウエンジニア転職のノウハウ
エンジニア転職のノウハウ
 
Ruby の文字列について
Ruby の文字列についてRuby の文字列について
Ruby の文字列について
 
Ruby on Rails のキャッシュ機構について
Ruby on Rails のキャッシュ機構についてRuby on Rails のキャッシュ機構について
Ruby on Rails のキャッシュ機構について
 
Ruby初心者からよく質問されること
Ruby初心者からよく質問されることRuby初心者からよく質問されること
Ruby初心者からよく質問されること
 
RubyGems と Bundler について
RubyGems と Bundler についてRubyGems と Bundler について
RubyGems と Bundler について
 
Ruby の正規表現について
Ruby の正規表現についてRuby の正規表現について
Ruby の正規表現について
 
Ruby での外部コマンドの実行について
Ruby での外部コマンドの実行についてRuby での外部コマンドの実行について
Ruby での外部コマンドの実行について
 
Ruby のワンライナーについて
Ruby のワンライナーについてRuby のワンライナーについて
Ruby のワンライナーについて
 
AWS のコスト管理をちゃんとしたくてやったこと
AWS のコスト管理をちゃんとしたくてやったことAWS のコスト管理をちゃんとしたくてやったこと
AWS のコスト管理をちゃんとしたくてやったこと
 
PostgreSQL のイケてるテクニック7選
PostgreSQL のイケてるテクニック7選PostgreSQL のイケてるテクニック7選
PostgreSQL のイケてるテクニック7選
 
HTTPと Webクローリングについて
HTTPと WebクローリングについてHTTPと Webクローリングについて
HTTPと Webクローリングについて
 
Rake
RakeRake
Rake
 
Active record query interface
Active record query interfaceActive record query interface
Active record query interface
 
Active Support のコア拡張機能について
Active Support のコア拡張機能についてActive Support のコア拡張機能について
Active Support のコア拡張機能について
 
Ruby ビジネス創出展 Ruby初心者向けプログラミングセミナー
Ruby ビジネス創出展 Ruby初心者向けプログラミングセミナーRuby ビジネス創出展 Ruby初心者向けプログラミングセミナー
Ruby ビジネス創出展 Ruby初心者向けプログラミングセミナー
 
RubyのDir、File、IO について
RubyのDir、File、IO についてRubyのDir、File、IO について
RubyのDir、File、IO について
 
Thread の利用事例紹介
Thread の利用事例紹介Thread の利用事例紹介
Thread の利用事例紹介
 
Ruby の制御構造とリテラルについて
Ruby の制御構造とリテラルについてRuby の制御構造とリテラルについて
Ruby の制御構造とリテラルについて
 

Recently uploaded

【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 

Recently uploaded (10)

【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 

ガス単独診断に学ぶ Vue js

  • 2. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 1自己紹介 川西 智也 エネチェンジ株式会社 チーフエンジニア Ruby関西代表 出自 新卒で入社したのは、関西電力 もともとはサーバサイド、インフラまわりを主に担当 最近はフロントエンドも開発するようになった Buzzった記事 Ruby のオススメの機能 7選 https://qiita.com/cuzic/items/a265f140fdff289d5c07 PostgreSQL のパフォーマンスチューニング https://qiita.com/cuzic/items/f9b846e6171a54079d77
  • 3. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 ガス単独診断とは 従来、電気・ガスの組合せで最適な会社を提案 電気はすでに切替済のユーザも多い ガスだけの組合せでの節約額の提示のニーズあり ガス単独診断をリリース! 初期版はチャットUIだった ただし、分岐もなく一直線で聞きたいことを聞くだけ チャットUIの意味なし VueJS を使った SPA に全面リニューアル! ユーザ利便性を向上! 2
  • 4. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 ガス単独診断(リニューアル後) 3 https://enechange.jp/gas
  • 5. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 computed プロパティを多用! computed プロパティはかなり便利! たとえ、1行の内容でも computed プロパティにする 読みやすく簡潔になる 結果がキャッシュされるので、高速化の効果もある 4 computed: { postcodeFull(){ return this.postcode1 + this.postcode2; }, isPostcodeValid(){ return this.postcodeFull.match(/^¥d{7}$/); }, isPostcodeErrorVisible(){ return this.tainted["postcode1"] && this.tainted["postcode2"] && !this.isPostcodeValid; }, … 郵便番号のエラー表示での使用例
  • 6. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 compted プロパティを watch ! VueJS では computed プロパティを watch できる 条件分岐をシンプルにできる 5 watch: { isPostcodeValid(current){ if(current){ this.getGasProviders(); this.resetSimulation(); } }, … 郵便番号入力後の処理での使用例
  • 7. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 $refs の活用 $refs で、特定の DOM 要素を参照可能 ここでは、郵便番号1を入力後、フォーカスを移動する ために $refs を使っている 6 watch: { isPostcode1Valid(current, old){ if(current){ this.$refs.postcode2.focus(); } }, … }, computed: { isPostcode1Valid(){ return this.postcode1.length === 3; }, <input type="text" … name="postcode2" v-model="postcode2" … ref="postcode2"> 郵便番号での $refs の使用例
  • 8. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 入力エラーのリアルタイム表示 1 / 2 7 <div … v-show="isPostcodeErrorVisible"><span> 郵便番号を入力してください</span></div> computed: { isPostcodeErrorVisible(){ return this.tainted["postcode1"] && this.tainted["postcode2"] && !this.isPostcodeValid; }, 入力誤りがあったとき、エラー文言を表示したい 最初から、エラー文言が表示されてるとウザい 入力後だけ、 エラー表示を 有効化 tainted という プロパティに 触ったか どうかを格納
  • 9. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 入力エラーのリアルタイム表示 2 / 2 @blur は v-on:blur の syntax sugar blur イベントをフックして、特定の処理を実行できる this.$set(this.tainted, fieldname, true); は this.tainted[fieldname] = true と同じ意味 $set を使うと computed 等の再計算が実行される 8 methods: { doTaint(event){ if(event.target.value){ const fieldname = event.target.name; this.$set(this.tainted, fieldname, true); } } … <input type="text" … name="postcode2" v-model="postcode2" … @blur="doTaint" ref="postcode2"> エラー表示での @blur イベントの使用例
  • 10. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 結果は1行ごとに v-component として設計 Vueコンポーネントをどう分割するか? 設計結果 入力: 1つの Vue コンポーネント 結果: 1行(1つのガスプラン)ごとにコンポーネント化 computed プロパティの機能を活用し、 View 側をシンプルに、見通しよく記述 9 <ul class="m__plans-container"> <li v-for="result in results"> <% if is_pc? %> <plans-finder-item-pc :result="result" /> <% else %> <plans-finder-item-smp :result="result" /> <% end %> </li> </ul> 結果ごとに Vue コンポーネントでレンダリング
  • 11. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 x-template の活用 10 <script type="text/x-template" id="plans-finder-item-pc"> <%= render 'plans_finder_item_pc' %> </script> <script type="text/x-template" id="plans-finder-item-smp"> <%= render 'plans_finder_item_smp' %> </script> 結果画面のマークアップをどう記述するか? x-template を使って、そのまま従来の View を活用 .vue などは逆に活用せず Ruby on Rails の従来の View と同じ運用の方が、 トータルで分かりやすいと判断した 従来の Rails プロジェクトで開発していた人にとっての とっつきやすさを重視 x-template の活用の例
  • 12. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 Spread演算子を使った共通化 ES2015 の Spread 演算子を使って、オブジェクトリテ ラルの一部を共通的に利用 相違点は、ID だけ。 すっきり! 11 const plansFinderItemPc = { template: "#plans-finder-item-pc", ...plansFinderItemCommon }; const plansFinderItemSmp = { template: "#plans-finder-item-smp", ...plansFinderItemCommon }; Vue.component('plans-finder-item-pc', plansFinderItemPc); Vue.component('plans-finder-item-smp', plansFinderItemSmp); モバイルと PC で、共通の設定を利用する例
  • 13. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 Filter の活用 一部の処理は View 側で頻出する(例: カンマ区切り) メソッド呼び出しは、読みにくい 右から左に進むと思考が止まる Filter を活用! 左から右に進む!読みやすい! 12 filters: { numberWithDelimiter(value){ return value.toString().replace(/¥B(?=(¥d{3})+(?!¥d))/g, ","); }, abs(value){ return Math.abs(Number(value)); } <span class="value">{{ actualYearSaving | abs | numberWithDelimiter }}</span><span class="unit">円</span><span v- if="isCheaper">節約</span> <span v-else>割高</span> Filter の活用例
  • 14. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 番外編 lodash の活用 Lodash はすごく便利だった。オススメ _.debounce _.differenceBy _.each _.find _.filter _.isEmpty _.map _.reject _.some _.sortBy 13
  • 15. Otemachi.rb #1 発表資料 「ガス単独診断に学ぶ VueJS」 14ガス単独診断全面リニューアルの感想 VueJS を活用して、全面リニューアルを実施した 2週間で全面リニューアルが完了でき、 VueJS の開発生産性の高さを実感した 特に computed プロパティが非常に便利だった View 側のコードをシンプルにできた