@converse/skeletor 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,16 +1,27 @@
1
1
  # Skeletor
2
2
 
3
- [![XMPP Chat](https://inverse.chat/badge.svg?room=discuss@conference.conversejs.org)](https://inverse.chat/#converse/room?jid=discuss@conference.conversejs.org)
3
+ [![XMPP Chat](https://conference.conversejs.org/muc_badge/discuss@conference.conversejs.org)](https://inverse.chat/#converse/room?jid=discuss@conference.conversejs.org)
4
4
  [![Travis](https://api.travis-ci.org/conversejs/skeletor.png?branch=master)](https://travis-ci.org/conversejs/skeletor)
5
5
 
6
- Skeletor is a [Backbone](http://backbonejs.org) fork.
6
+ Skeletor is a [Backbone](http://backbonejs.org) fork that adds various improvements and features.
7
7
 
8
- Its goal is to modernize and componentize Backbone.
8
+ ## Introduction
9
9
 
10
- Original Backbone Views can't be rendered in a nested and declarative way,
11
- similarly to how components are rendered in React and other frameworks.
10
+ The goal of Skeletor is to modernize Backbone and to allow you to stop
11
+ writing imperative view code (e.g. manually adding and removing DOM nodes)
12
+ and instead start writing declarative, component-based code that automatically
13
+ updates only the changed parts of the DOM, similarly to basically all modern
14
+ JavaScript frameworks.
12
15
 
13
- We can solve this by making Views web components. Check out the `ElementView` class, which does this.
16
+ The original Backbone Views aren't components can't be rendered in a nested and
17
+ declarative way. Instead, it's up to you to manually make sure that these views
18
+ are rendered in the correct place in the DOM. This approach becomes unwieldy,
19
+ difficult and fragile as your site becomes larger and more complex.
20
+
21
+ Skeletor solves this by creating a new type of View, called `ElementView`,
22
+ which is very similar to the original Backbone `View` but which is also a web
23
+ component that gets instantiated automatically as soon as its rendered in the
24
+ DOM.
14
25
 
15
26
  ## Why bother?
16
27
 
@@ -18,7 +29,7 @@ The goal of this fork is to allow the Converse team to gradually update the [Con
18
29
  XMPP webchat client to use web components (using [LitElement](https://lit-element.polymer-project.org/))
19
30
  without requiring us to put everything on hold in order to do a massive rewrite.
20
31
 
21
- The end-goal is to not have any Backbone/Skeletor Views at all, only LitElement components.
32
+ The end-goal is to not have any Skeletor Views at all, only LitElement components.
22
33
 
23
34
  We can cheat a little by letting the existing Views also be web components
24
35
  (more accurately, "custom elements"), this allows us to declaratively render the
@@ -60,3 +71,55 @@ UI, while we're progressively getting rid of the views.
60
71
  5. The `partition` and `invokeMap` methods have been removed.
61
72
 
62
73
  ![](https://raw.githubusercontent.com/conversejs/skeletor/master/images/skeletor3.jpg)
74
+ ### ElementView example
75
+
76
+ The ElementView looks very similar to a normal Backbone View.
77
+
78
+ Since it's a web component, you need to call `CustomElementRegistry.define` to
79
+ register it.
80
+
81
+ The `this` variable for the ElementView is the custom DOM element itself,
82
+ in this case, `<my-custom-button>`.
83
+
84
+ So there is no `el` attribute and `this.el` will be undefined. Whereever in a
85
+ Backbone View you'd use `this.el`, with an ElementView you'd just use `this`.
86
+
87
+
88
+ ```javascript
89
+
90
+ import { ElementView } from '@converse/skeletor/src/element.js';
91
+ import { render } from 'lit';
92
+ import { html } from 'lit';
93
+
94
+ export default class MyCustomButton extends ElementView {
95
+ events = {
96
+ 'click .button': 'onButtonClicked'
97
+ }
98
+
99
+ async initialize () {
100
+ this.model = new Model({ count: 0 });
101
+ this.listenTo(this.model, 'change', this.render)
102
+ }
103
+
104
+ render () {
105
+ return render(html`<button class="button">I've been clicked ${model.get('count')} times!</button>`, this);
106
+ }
107
+
108
+ onButtonClicked () {
109
+ this.model.save('count', this.model.get('count')+1);
110
+ }
111
+ }
112
+
113
+ CustomElementRegistry.define('my-custom-button', MyCustomButton);
114
+ ```
115
+
116
+ You can now put your custom element in the DOM, and once the DOM is loaded by
117
+ the browser, your ElementView will automatically be instantiated and
118
+ `initialize` will be called.
119
+
120
+
121
+ ```html
122
+ <div>
123
+ <my-custom-button></my-custom-button>
124
+ </div>
125
+ ```