./catberry_stores/
doge/
Wow.js
Such.js
Store.js
grumpy-cat/
No.js
class MyStore {constructor(locator) {this.$lifetime = 60000; // how long to cache the data (ms)}load() { /* returns data (or promise) for components */ }handleAddItem(args) { /* handles "add-item" */ }}module.exports = MyStore;
ThehandleAddItem(args) {// you can get routed parameters from URIthis.$context.state.newsCategory;// and notify about changesthis.$context.changed();}
$context is a public interface of the framework.
// you define a route'/some/:id[Store1,Store2]/actions?q=:query[Store1]'// go to this link'/some/123/actions?q=find-a-cat'// then Store1 and Store2 will havethis.$context.state.id === '123'// and only Store1 will havethis.$context.state.query === 'find-a-cat'
| Feature | Cat | Web | |
| Define custom elements | Yes | Yes | |
| Have server-side rendering | Yes | No | |
| Support several template engines | Yes | No | |
| Organized like directories in a project | Yes | No | |
| Can be installed/published using NPM | Yes | No | |
| Can be auto-discovered in a project | Yes | No | |
| Shadow DOM (styles isolation) | No | Yes |
hello-world/
index.js # exports a class
template.hbs # is rendered inside the component's tag
error.hbs # is rendered instead if error occurs
cat-component.json # defines the component
<cat-hello-world id="uniq-id" cat-store="some/Store"></cat-hello-world>
The template will be rendered inside the tag and if it contains other components' tags the process repeats recursively.
All tag attributes are accessible via this.$context.attributes
class MyComponent {constructor(locator) { /* resolve smth from the locator */ }render() { /* gets data (or promise) for the template */ }bind() { /* component appears in DOM */ }unbind() { /* component is removed from DOM */ }}module.exports = MyComponent;
render() {return this.$context.getStoreData().then(data => /* success, the Store returned data */ ).catch(error => /* no luck :( */ );}
this.$context.sendAction('add-item', item).then(result => /* success, we have a result */ ).catch(error => /* no luck :( */ );
// service name, class, isSingletonapp.locator.register('uhr', UHR, true);// resolve it in a constructorclass MyComponent {constructor(locator) {this._uhr = locator.resolve('uhr');}}
developers.google.com
catberry-example$ npm -g install catberry-cli$ catberry init example
github.com/catberry/catberry