Catberry는 "동형/범용"웹 응용 프로그램을 만드는 데 도움이되었습니다.
간단히 말해서, 동형/유니버설 애플리케이션은 서버 및 클라이언트 환경에서 동일한 코드베이스를 사용하여 클라이언트가 "단일 페이지 응용 프로그램"으로 보는 것을 렌더링하는 앱입니다.
다음 명령을 사용하여 Catberry 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 페이지를 가져오고 나머지 시간 내내 전체 페이지가 응용 프로그램과 함께 사용 된 API 서비스에서 순수한 데이터 만 수신하는 브라우저에서 변경되고 있습니다.
Catberry의 프로그레시브 렌더링 엔진 덕분에 사용자는 각 구성 요소가 전체 페이지를 대기하지 않으면 템플릿을 렌더링하는 것처럼 Component의 서버 구성 요소에서 페이지를 수신합니다.
Catberry는 2 개의 마지막 버전의 최신 브라우저와 IE 11을 지원합니다. Babel Babel-Preset-Env Preset에 따라 프로젝트에 .babelrc 파일을 넣는 것을 무시할 수있는 구성에 따라 다릅니다.
Catberry에 기여하는 방법에는 여러 가지가 있습니다.
Denis rechkunov [email protected]