hello-world/
assets/
hello.svg
world.svg
index.js
template.hbs
error.hbs
cat-component.json
{"name": "hello-world","logic": "./index.js","template": "./template.hbs","errorTemplate": "./error.hbs"}
В этот тэг отрендерится шаблон, который может содержать тэги компонентов, процесс повторяется рекурсивно<cat-hello-world id="uniq-id"cat-store="some/Store"any-attribute="any-value"></cat-hello-world>
documentdocument нельзя использовать тэгомdocument нельзя привязать к Storehead привязывается к head-элементуmodule.exports = HelloWorld;function HelloWorld() {...}// этапы жизни компонентаHelloWorld.prototype.render = function () {...}HelloWorld.prototype.bind = function () {...}HelloWorld.prototype.unbind = function () {...}
HelloWorld.prototype.render = function () {// может вернуть данные для шаблона// или Promise на нихreturn {hello: 'world'};};
HelloWorld.prototype.bind = function () {// может вернуть карту событий// для дочерних элементов или Promise на нееreturn {click: {'div.clickable': this.clickHandler}};};
HelloWorld.prototype.unbind = function () {// здесь нужно прибраться, если вы// что-то делали в bind помимо карты событий// события из карты отвязываются автоматически};
./catberry_stores/
doge/
Wow.js
Such.js
Store.js
grumpy-cat/
No.js
doge/Wowcat-storemodule.exports = Wow;function Wow() {...}// время актуальности данных в мсWow.prototype.$lifetime = function () {...}// загрузка данныхWow.prototype.load = function () {...}// обработка ActionWow.prototype.handleVeryAction = function () {...}
Wow.prototype.load = function () {...}// запрашивает данные, например по REST// возвращает объект или Promisereturn {hello: 'world'};};
Wow.prototype.handleVeryAction = function () {...}// может запостить данные по REST// вернуть результат или Promisereturn {response: 'some'};};
Wow.prototype.handleVeryAction = function () {...}// а может отправить сигнал,// что Store изменилсяthis.$context.changed();};
this.$context.getStoreData().then(function () {// ура, Store дал данные});.catch(function (error) {// печаль :(});
this.$context.sendAction('item-submit', item).then(function () {// ура, Action обработался});.catch(function (error) {// печаль :(});
locator.register(‘uhr’, UHR);locator.registerInstance('uhr', new UHR());locator.resolve(‘uhr’);locator.resolveAll(‘uhr’);locator.resolveInstance(SomeConstructorDependsOnUHR);
function StoreConstructor ($uhr, someConfigSection) {// можно внедрять и использовать $uhr// и внедрять даже конфиг-секции}
document
catberry-todomvc$ npm -g install catberry-cli$ catberry init example
| catberry.github.io | |
![]() |
github.com/catberry/catberry (звезду, звезду поставьте) |