@converse/skeletor 0.0.8 → 1.0.0

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,66 +1,47 @@
1
1
  # Skeletor
2
2
 
3
3
  [![XMPP Chat](https://conference.conversejs.org/muc_badge/discuss@conference.conversejs.org)](https://inverse.chat/#converse/room?jid=discuss@conference.conversejs.org)
4
- [![Travis](https://api.travis-ci.org/conversejs/skeletor.png?branch=master)](https://travis-ci.org/conversejs/skeletor)
4
+ [![CI Tests](https://github.com/conversejs/skeletor/actions/workflows/karma-tests.yml/badge.svg)](https://github.com/conversejs/skeletor/actions/workflows/karma-tests.yml)
5
5
 
6
- Skeletor is a [Backbone](http://backbonejs.org) fork that adds various improvements and features.
6
+ Skeletor is a modernization of [Backbone](http://backbonejs.org)'s Models and Collections, which are used for managing state.
7
7
 
8
- ## Introduction
8
+ ## Installation
9
9
 
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.
15
-
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.
25
-
26
- ## Why bother?
27
-
28
- The goal of this fork is to allow the Converse team to gradually update the [Converse](https://conversejs.org)
29
- XMPP webchat client to use web components (using [LitElement](https://lit-element.polymer-project.org/))
30
- without requiring us to put everything on hold in order to do a massive rewrite.
10
+ ```
11
+ npm install @converse/skeletor
12
+ ```
31
13
 
32
- The end-goal is to not have any Skeletor Views at all, only LitElement components.
14
+ ## Changes from Backbone
33
15
 
34
- We can cheat a little by letting the existing Views also be web components
35
- (more accurately, "custom elements"), this allows us to declaratively render the
36
- UI, while we're progressively getting rid of the views.
16
+ We've made big, backwards incompatible changes in version 1.0.0:
37
17
 
38
- ![](https://raw.githubusercontent.com/conversejs/skeletor/master/images/skeletor2.jpg)
18
+ - Removed the old `View`
19
+ - Removed the old `Events` constructor function and instead added the `EventsEmitter` mixin class.
20
+ - Removed the `Router` and `History` classes.
21
+ - All other types (e.g. `Model`, `Collection`) are now ES6 classes.
39
22
 
40
- ## Sekeletor adds the following changes to Backbone
23
+ ### Sekeletor adds the following changes to Backbone
41
24
 
25
+ * Rewritten in TypeScript
42
26
  * Removes the dependency on jQuery
43
- * Instead of the `render` method Views can have a `toHTML` method which must return a [lit-html](https://lit-html.polymer-project.org/) `TemplateResult`.
44
27
  * Replaces [underscore](http://underscorejs.org) with [lodash](https://lodash.com)
45
28
  * Imports lodash methods individually to allow for tree-shaking
46
29
  * Uses the native browser API instead of lodash whereever possible
47
30
  * Drops support for older browsers (including IE) and uses ES6+ language features
48
- * Splits models, views and collections into separate modules
31
+ * Splits models and collections into separate modules
49
32
  * Adds the possibility to returns promises for asynchronous operations
50
- * Adds a new `ElementView` class, which is a like a Backbone View, but doubles
51
- as an instance of HTMLElement and can be used to register a custom element or
52
- web-component.
53
33
 
54
- ![](https://raw.githubusercontent.com/conversejs/skeletor/master/images/skeletor.jpg)
55
-
56
- ### Backwards incompatible changes
34
+ ### Other backwards incompatible changes
57
35
 
58
36
  * Collection.prototype.forEach no longer returns the items being iterated over.
59
37
  If you need that, use `map` instead.
60
- * The `chain` method on Models has been removed.
38
+ * The `chain`, `clone` and `escape` methods on Models have been removed.
39
+ * The `clone` method has also been removed from Collections
61
40
  * The `inject`, `foldl` and `foldr` methods on Collections has been removed. You can use `reduce` instead.
62
41
  * Removed the `sample`, `take`, `tail` and `initial` method on Collections.
63
42
  * Removed the `without`, `reject` and `select` methods on Collections, use `filter`.
43
+ * Removed the `.extend()` method on `Model` and `Collection`.
44
+ * Models and Collections should be defined via `class .. extends` syntax.
64
45
 
65
46
  #### Changes due to using Lodash instead of Underscore
66
47
 
@@ -70,56 +51,4 @@ UI, while we're progressively getting rid of the views.
70
51
  4. Use `includes` instead of `contains`
71
52
  5. The `partition` and `invokeMap` methods have been removed.
72
53
 
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
- ```
54
+ ![](https://raw.githubusercontent.com/conversejs/skeletor/master/images/skeletor2.jpg)