Catberryは、「同型/ユニバーサル」Webアプリケーションの作成を支援するために開発されました。
短いストーリーの要するに、Isomorphic/Universalアプリケーションは、サーバー環境とクライアント環境の両方で同じコードベースを使用して、クライアントが「シングルページアプリケーション」と見なすものをレンダリングするアプリです。
次のコマンドを使用してキャットベリーCLIをインストールします。
npm install -g catberry-cliCatberry CLIを使用して、このようなハンドルバーサポートを備えた空のプロジェクトを作成します。
catberry init empty-handlebarsまたは、GitHub APIを使用して動作するアプリケーションの例:
catberry init exampleまた、すべてのテンプレートのリストを取得できます。
catberry init ? 詳細については、Catberryのドキュメントをご覧ください。
'use strict' ;
class CoolComponent {
/**
* Creates a new instance of the "CoolComponent" component.
* @param {ServiceLocator} locator The service locator for resolving dependencies.
*/
constructor ( locator ) {
// you can resolve any dependency from the locator.
}
/**
* Gets data for the template.
* This method is optional.
* @returns {Promise<Object>|Object|null|undefined} Data for the template.
*/
render ( ) {
return this . $context . getStoreData ( ) ;
}
/**
* Returns event binding settings for the component.
* This method is optional.
* @returns {Promise<Object>|Object|null|undefined} Binding settings.
*/
bind ( ) {
return {
// CSS selector
'.clickable' : ( ) => window . alert ( 'Ouch!' ) ;
}
}
/**
* Cleans up everything that has NOT been set by .bind() method.
* This method is optional.
* @returns {Promise|undefined} Promise of nothing.
*/
unbind ( ) {
// nothing to do here we have used bind properly
}
}
module . exports = Some ;コンポーネントはカスタムタグとして使用されます。
< cat-cool id =" unique-value " cat-store =" group/CoolStore " > </ cat-cool > 'use strict' ;
class CoolStore {
/**
* Creates a new instance of the "CoolStore" store.
* @param {ServiceLocator} locator The service locator for resolving dependencies.
*/
constructor ( locator ) {
/**
* Current universal HTTP request for environment-independent requests.
* @type {UHR}
* @private
*/
this . _uhr = locator . resolve ( 'uhr' ) ;
/**
* Current lifetime of data (in milliseconds) that is returned by this store.
* @type {number} Lifetime in milliseconds.
*/
this . $lifetime = 60000 ;
}
/**
* Loads data from a remote source.
* @returns {Promise<Object>|Object|null|undefined} Loaded data.
*/
load ( ) {
// Here you can do any HTTP requests using this._uhr.
// Please read details here https://github.com/catberry/catberry-uhr.
}
/**
* Handles an action named "some-action" from any component or store.
* @returns {Promise<Object>|Object|null|undefined} Response to the component/store.
*/
handleSomeAction ( ) {
// Here you can call this.$context.changed() if you're sure'
// that the remote data on the server has been changed.
// You can additionally have many handle methods for other actions.
} ;
}
module . exports = Some ; Catberryは、履歴APIなどの特定のHTML5機能を使用するため、サーバー上のブラウザのページをレンダリングできますが、クライアント側のJavaScriptアプリケーションでは古いブラウザの部分的なサポートのみが可能です。
Catberryフレームワークの主な目標は、新しいテクノロジーの全力を使用し、ユーザーに可能な限り最高のエクスペリエンスを提供することです。
実際、ユーザーはサーバーからHTMLページを1回だけ取得し、残りの時間のすべての時間は、アプリケーションで使用されるAPIサービスから純粋なデータのみを受信するブラウザでページ全体が変更されています。
Catberryのプログレッシブレンダリングエンジンのおかげで、ユーザーは各コンポーネントがページ全体が構築されていないテンプレートをレンダリングするのと同じくらい速くコンポーネントでサーバーコンポーネントからページを受信します。
Catberryは、最新のブラウザとIE 11の2つの最後のバージョンをサポートしています。これは、プロジェクトに.babelrcファイルの配置を上書きできる構成Babel Babel-Preset-envプリセットに依存します。
キャットベリーに貢献する方法はたくさんあります:
Denis Rechkunov [email protected]