Skip to content

Instantly share code, notes, and snippets.

@hikarock
Created August 17, 2014 10:49
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hikarock/818b67c91e98fd74929f to your computer and use it in GitHub Desktop.
Save hikarock/818b67c91e98fd74929f to your computer and use it in GitHub Desktop.
rendr-examplesメモ

rendr-examplesを眺めてみたメモ。

00. simple

基本的な構成。npm install & grunt serverhttp://localhost:3030で起動する(以下のexampleも同様)。

01. config

00ではindex.jsに直接書かれていたdataAdapterConfig/configディレクトリ内のファイルに分離。 NODE_ENVの値で本番/開発環境の設定ファイル切り替えを行う

02. middleware

middlewareの追加方法のサンプル。 /server/middlewareディレクトリが追加。index.js内で以下の二つの関数を呼び出している。

  • リクエストのlocaleを設定するaddLocaleToRequest
  • ダミーのAPIからデータを取得するfetchDataForApp
    • fetchDataForAppはmodel/view/controllerから利用できるようになる

03. sessions

sessionを使ったサンプル。indexにThere have been 4 requests to this app in your session.と表示され、リロードのたび更新される。 express.cookieParserexpress.sessionを使う。configにsession.secretを追記している。 カウンターは/server/middleware/incrementCounter.jsindex.jsから呼び出して更新している。

04. entrypath

/app以下にmainlanding_pageディレクトリができている。アプリをmainApplandingPageAppの二つ起動している。 landingPageAppは普通のExpressアプリ(http://localhost:3030/landing_page)。mainAppの方はRendrアプリ。 Rendrアプリのconfigは/app/main/index.jsにて設定。

05. requirejs

requirejsを使ったサンプル(標準はCommonJS)。package.jsonに以下が追記されている。

  • requirejs
  • grunt-contrib-requirejs
  • grunt-rendr-requirejs

00のサンプルのroutes.jsなどを見比べると違いがよくわかる。

06. appview

app/views/app_view.jsが追加されている。app.jsにgetAppViewClass関数を追記してnode_modules/rendr/shared/app.jsのgetAppViewClassをオーバーライドしている。app/views/app_view.jsではpostInitializeの挙動を変えている(ロード中に画面の右上にloading…の文字を表示している)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment