catberry
viders and more
Catberry的開發是為了幫助創建“同構/通用” Web應用程序。
長篇小說簡短,同構/通用應用程序是在服務器和客戶端環境上使用相同代碼庫來渲染客戶端將視為“單頁應用程序”的應用程序。
使用以下命令安裝Catberry CLI:
npm install -g catberry-cli使用Catberry 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能夠為服務器上的任何瀏覽器渲染頁面,但由於使用某些HTML5功能,例如歷史記錄API,因此客戶端JavaScript應用程序只能提供舊瀏覽器的部分支持。
Catberry框架的主要目標是使用新技術的全部功能,並為用戶提供最佳的體驗。
實際上,用戶僅從服務器獲得HTML頁面,整個頁面的其餘時間都在瀏覽器中更改,該瀏覽器僅接收應用程序中使用的API服務的純數據。
多虧了Catberry的漸進式渲染引擎,用戶可以按組件從服務器組件中接收到一個頁面,因為每個組件都會呈現其模板不等待整個頁面的構建。
Catberry支持2個現代瀏覽器和IE 11的最後版本。這取決於Babel Babel-Preset-env Prest,您可以覆蓋哪種配置,將.babelrc文件放入項目中。
有很多方法可以為catberry做出貢獻:
denis rechkunov [email protected]