Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
About Integrant
Search
ayato
March 13, 2017
Programming
610
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
About Integrant
ayato
March 13, 2017
More Decks by ayato
See All by ayato
マイクロサービス内で動くAPIをF#で書いている
ayato0211
1
1.7k
Clojureという言語が私逹にもたらしたもの
ayato0211
6
3.2k
3年間考え続けてきたWebアプリケーションにおけるテストの話
ayato0211
3
320
Re:REPL-Driven Development
ayato0211
3
1.4k
Meta Template Engine
ayato0211
2
1.2k
超変換! Hiccup data structure!!
ayato0211
2
680
Muscle Assert
ayato0211
0
340
Clojureを用いたWebアプリケーション開発
ayato0211
2
3.3k
翻訳にまつわるエトセトラ
ayato0211
6
1.3k
Other Decks in Programming
See All in Programming
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
350
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
180
JRuby: Past, Present, and Future
headius
0
220
mrbgem 三角測量 開発
ogom
0
200
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
230
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
910
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
160
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
740
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
360
Androidだけじゃない、DroidKaigiで広がった私の技術スタック
akkeylab
0
120
Embedded Swiftで作る自作USBデバイス によるiOSデバイスの自動テスト / iOSDC Japan 2026 glassfiber
glassfiber
0
290
Featured
See All Featured
Writing Fast Ruby
sferik
630
63k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Speed Design
sergeychernyshev
33
2.1k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
250
Automating Front-end Workflow
addyosmani
1369
210k
Building Adaptive Systems
keathley
44
3.2k
The SEO Collaboration Effect
kristinabergwall1
1
590
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
620
YesSQL, Process and Tooling at Scale
rocio
174
15k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Accessibility Awareness
sabderemane
1
230
Docker and Python
trallard
47
4.2k
Transcript
*OUFHSBOU ʹ͍ͭͯ !@BZBUP@Q$ZCP[V4UBSUVQT JOD
自己紹介 •あやぴー •朝ジムを倒しまくってる •普段はComponentベースでシステム開発
Integrant概要
Integrantとは •Jamesオジサンが作った新しいデータ駆動 アーキテクチャなマイクロフレームワーク •つまり、ライフサイクルを管理するライブラリ •Componentで指摘された課題を解決しようとしたもの •システムがデータから組み立てられる •各コンポーネントは必ずしもマップやレコードである 必要はない
データによるシステム定義 •ednでシステムを定義できる {:adapter/jetty {:port 8080, :handler #ref :handler/greet} :handler/greet {:name
"Alice"}}
Multimethodによるコンポーネント定義 •レコードやマップに限らず関数やただの数値などもコン ポーネントにすることが可能 (require '[ring.jetty.adapter :as jetty] '[ring.util.response :as resp])
(defmethod ig/init-key :adapter/jetty [_ {:keys [handler] :as opts}] (jetty/run-jetty handler (-> opts (dissoc :handler) (assoc :join? false)))) (defmethod ig/init-key :handler/greet [_ {:keys [name]}] (fn [_] (resp/response (str "Hello " name))))
一時停止と再開のサポート •再起動が遅くなるのを回避できる •suspend-key!とresume-keyがポイント •初期化処理にも多少影響がある
一時停止と再開のサポート (defmethod ig/init-key :adapter/jetty [_ opts] (let [handler (atom (delay
(:handler opts))) options (-> opts (dissoc :handler) (assoc :join? false))] {:handler handler :server (jetty/run-jetty (fn [req] (@@handler req)) options)})) (defmethod ig/halt-key! :adapter/jetty [_ {:keys [server]}] (.stop server)) (defmethod ig/suspend-key! :adapter/jetty [_ {:keys [handler]}] (reset! handler (promise))) (defmethod ig/resume-key :adapter/jetty [key opts old-opts old-impl] (if (= (dissoc opts :handler) (dissoc old-opts :handler)) (do (deliver @(:handler old-impl) (:handler opts)) old-impl) (do (ig/halt-key! key old-impl) (ig/init-key key opts))))
Componentと比較して⚔
良いところ •データでシステムを記述できる •どんなモノでもコンポーネントにできる •心理的な負担が減る
悪いところ •明示的にコンポーネントの名前空間を読み込む必要性
変わらなかったこと •あるコンポーネントに依存したいならば それ自身をコンポーネントとして定義する必要がある
Integrantはこう使う (と良いかも)
独自のns loaderを作る •デフォルトでついてくるのは使い勝手が悪い •完全修飾されたキーワードは設定ファイルに書き難い •開発時にシステムからコンポーネントを取り出すのも苦 •例えばbultitudeを利用して任意のprefix付きnsを ロードするようなbootstrap機能を実装する
同じコンポーネントを複数作る •マルチメソッドを大量に用意する? •No •任意の親を持つ子のキーワードを複数deriveしておく •注意点 •複数の子で設定を書く場合は親のキーワードを 設定ファイルに書けない •refに対して子のキーワードを明示
同じコンポーネントを複数作る (derive :demo/master-db :demo/db) (derive :demo/read-db-1 :demo/db) (derive :demo/read-db-2 :demo/db)
(defmethod ig/init-key :demo/db [_ opts] ...) (ig/init {:demo/read-db-1 {...} :demo/read-db-2 {...} :demo/master-db {...} :demo/get-user-handler {:db (ig/ref :demo/read-db-1)} :demo/get-company-handler {:db (ig/ref :demo/read-db-2)} :demo/update-user-handler {:db (ig/ref :demo/master-db)}}
テストでコンポーネントを差し替える •deriveでok
baumと組み合わせる •baumは設定ファイルを素敵にする拡張可能な DSLライブラリ •環境変数などを取得できる •baumのカスタムリーダーとして integrant.core/refをラップする
baumと組み合わせる {$override* "dev-resources/config-local.edn" :demo/server {:port 3000 :handler #igref :demo/endpoint} :demo/database
{:dbtype "postgresql" :dbname "my_blog" :user #env :db-user :password #env :db-password} :demo/endpoint {:db #igref :demo/database}}
まとめ •Componentにあった心理的な負担が減った •これが1番いいかと言われると疑問 •Arachne的なアプローチにも期待したい