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]