4月メモ・リンク集
4 月に調べたことのメモです。
Angular 関連
- angular-rx-next-error-complete-finalize - StackBlitz
- complete と finalize の挙動確認サンプル
- next => next => … => error => finalize
- next => next => … => complete => finalize
- complete と finalize の挙動確認サンプル
Angular 6
リリース前の予習に。
- Angular 6 — What can we expect? – Jeroenouw – Medium
- Main new features
Angular elements, CDK, Ivy renderer, Bazel & Closure compiler, ng update & ng add, RXJS 6, Webpack 4, TypeScript 2.7 support
- Main new features
- Are you ready for Angular 6? – Valentyn Yakymenko – Medium
RouterModule Changes
FormsModule Changes
Angular CLI 1.7
- Setting budgets with new Angular CLI – frontend.coach – Medium
With the new 1.7 release of @angular/cli we now have a possibility to add a “weight watcher” for our scripts.
- Angular v6 で導入される Tree-Shakable DI の紹介 - lacolaco
モーダルの状態を ngrx で管理する
- UI state management with Redux in Angular 4 (Example) | hack.guides()
core
=>layout
=>openedModalName: string
という state を用意openedModalName
を受け取るコンポーネントをAppComponent
に配置@Input
の setter でうけとりモーダルの Open/Close をハンドリングする
- angular-modal-state-with-ngrx-wip - StackBlitz
- ngrx で管理する方法と今まで通りの方法の比較デモ
- (途中まで)
- 今の考え、実装に必要なタスク
ngrx の状態管理を Router (URL) 起点にする
- angular-ngrx-router-state - StackBlitz
- Using NgRx 4 to Manage State in Angular Applications を参考にしたサンプル
- 階層構造を少し複雑にしている
/projects/:id/dashboard
,/projects/:id/issues;page=1
など- (まあサンプルは途中なんですけどね)
foo
,bar/:id
まで
/projects/:id/issues;page=1
のような URL で 取得するデータが id と page に関係する場合
Rails 関連
- Rails チュートリアル復習用メモ - ryotah’s blog
- Ruby on Rails チュートリアル:実例を使って Rails を学ぼう を読んだ時の復習メモ
- Active Record バリデーション | Rails ガイド
update_attribute
はバリデーションを実行しない
マイグレーション
- Railsのmigrationの基本とレシピ集 - Rails Webook
※upとdownは、changeメソッドの代わりに使います。 upはrake db:migrateの実行時に実行され、downはrake db:rollback時に実行されます。
データの投入 rake db:seedコマンド
rake db:drop
,rake db:schema:load
Active Record クエリインターフェイス
- Active Record クエリインターフェイス#OR条件 | Rails ガイド
- Rails4.2 で like 句のサニタイズをする - hotoolong’s blog
- where で複数条件検索 - Qiita
Active Record コールバック
class Order < ApplicationRecord before_save :normalize_card_number, if: :paid_with_card? end
class Order < ApplicationRecord before_save :normalize_card_number, if: Proc.new { |order| order.paid_with_card? } end
JSのテスト 関連
- Getting Started · Jest
- 初めて使ってみた
- 日本語のドキュメントもしっかりして学習コストが低そう
- jasmineっぽい?
- angular - Why use spyOn instead of jasmine.createSpy? - Stack Overflow
- jasmine.createSpy => 裸のスパイ関数
spyOn
を利用してインスタンスメソッドの挙動を確認する
it('calls self bar method', () => { spyOn(Foo.prototype, 'bar'); new Foo(); expect(Foo.prototype.bar).toHaveBeenCalled(); });
Docker
- Docker 一括削除コマンドまとめ - Qiita
docker system prune
- docker-compose run | Docker Documentation
docker-compose run
- サービス群が起動していない状況でも動かせる
—rm
Remove container after run. Ignored in detached mode.
Circle CI
- Session not created exception: Chrome version must be >= 62.0.3202.0 - Bug Reports - CircleCI Community Discussion
- Circle Ci で提供されている Docker image の Chrome をアップデートする
- run: name: Install Chrome command: | wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add - sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' sudo apt-get update sudo apt-get -y install google-chrome-stable
TypeScript
http://www.typescriptlang.org/docs/handbook/advanced-types.html#mapped-types
Mapped types は便利。
type Keys = 'option1' | 'option2'; type Flags = { [K in Keys]: boolean }; // 以下は自分の利用例 export const DateFormats: { [key in DateFormatTypes]: DateTimeFormatOptions } ... export const DateFormats: { [key in DateFormatTypes]: DateTimeFormatOptions }
Partial<T>
も最近使うようになった。
Note that Readonly
and Partial are so useful, they are included in TypeScript’s standard library along with Pick and Record:
(Pick
, Record
はまだ使ったことない)
その他
- GitHub - alexjoverm/typescript-library-starter: Starter kit with zero-config for building a library in TypeScript, featuring RollupJS, Jest, Prettier, TSLint, Semantic Release, and more!
- 依存ライブラリがあるが、自分が作成するライブラリに取り込みたくない場合
rollup.config.ts
のexternal
設定を変更する
- 依存ライブラリがあるが、自分が作成するライブラリに取り込みたくない場合