@blockquote-web-components/blockquote-controller-rxjs 1.0.22 → 1.0.24
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 +68 -40
- package/package.json +35 -15
- package/src/BlockquoteControllerRxjs.js +67 -70
- package/README.js +0 -72
package/README.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# blockquote-controller-rxjs
|
|
2
|
-
|
|
3
1
|
# BlockquoteControllerRxjs
|
|
4
2
|
|
|
5
3
|

|
|
@@ -12,57 +10,87 @@
|
|
|
12
10
|
`BlockquoteControllerRxjs` provides a subscribe method to which pass the property we want to
|
|
13
11
|
assign values to and the Observable we want to subscribe.
|
|
14
12
|
|
|
15
|
-
- It works with [reactive properties](https://lit.dev/docs/components/properties/) and
|
|
13
|
+
- It works with [reactive properties](https://lit.dev/docs/components/properties/) and non-reactive properties
|
|
16
14
|
- It ignores calls on the same property with the same Observable
|
|
17
|
-
- It unsubscribes from old observable if called again on the same property with different Observable
|
|
15
|
+
- It unsubscribes from the old observable if called again on the same property with a different Observable
|
|
18
16
|
- It unsubscribes when the component is removed
|
|
19
17
|
|
|
20
18
|
## Usage
|
|
21
19
|
|
|
22
20
|
```js
|
|
23
21
|
class BlockquoteControllerRxjsDemo extends LitElement {
|
|
24
|
-
static get is() {
|
|
25
|
-
|
|
26
|
-
}
|
|
22
|
+
static get is() {
|
|
23
|
+
return 'blockquote-controller-rxjs-demo';
|
|
24
|
+
}
|
|
27
25
|
|
|
28
|
-
static get properties() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
26
|
+
static get properties() {
|
|
27
|
+
return {
|
|
28
|
+
_pos: {
|
|
29
|
+
type: Object,
|
|
30
|
+
attribute: false,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
36
34
|
|
|
37
|
-
constructor() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
35
|
+
constructor() {
|
|
36
|
+
super();
|
|
37
|
+
this.rx = new BlockquoteControllerRxjs(this);
|
|
38
|
+
this._pos = { x: 0, y: 0 };
|
|
39
|
+
this.values$ = fromEvent(window, 'mousemove').pipe(
|
|
40
|
+
map(({ clientX, clientY }) => ({ x: clientX, y: clientY })),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
45
43
|
|
|
46
|
-
connectedCallback() {
|
|
47
|
-
|
|
44
|
+
connectedCallback() {
|
|
45
|
+
super.connectedCallback();
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
47
|
+
// Property and Observable.
|
|
48
|
+
this.rx.subscribe('_pos', this.values$);
|
|
49
|
+
}
|
|
52
50
|
|
|
53
|
-
render() {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
51
|
+
render() {
|
|
52
|
+
return html`
|
|
53
|
+
<p>The mouse is at:</p>
|
|
54
|
+
<pre>
|
|
55
|
+
x: ${this._pos.x}
|
|
56
|
+
y: ${this._pos.y}
|
|
57
|
+
</pre
|
|
58
|
+
>
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
63
61
|
}
|
|
64
62
|
```
|
|
65
63
|
|
|
66
|
-
## Exports
|
|
67
64
|
|
|
68
|
-
|
|
65
|
+
### `src/BlockquoteControllerRxjs.js`:
|
|
66
|
+
|
|
67
|
+
#### class: `BlockquoteControllerRxjs`
|
|
68
|
+
|
|
69
|
+
##### Fields
|
|
70
|
+
|
|
71
|
+
| Name | Privacy | Type | Default | Description | Inherited From |
|
|
72
|
+
| ---- | ------- | ---- | ----------- | ----------- | -------------- |
|
|
73
|
+
| | | | `new Map()` | | |
|
|
74
|
+
|
|
75
|
+
##### Methods
|
|
76
|
+
|
|
77
|
+
| Name | Privacy | Description | Parameters | Return | Inherited From |
|
|
78
|
+
| ------------------ | ------- | ----------- | ------------------ | ------ | -------------- |
|
|
79
|
+
| `subscribe` | | | `propKey, stream$` | | |
|
|
80
|
+
| `hostDisconnected` | | | | | |
|
|
81
|
+
|
|
82
|
+
<hr/>
|
|
83
|
+
|
|
84
|
+
#### Exports
|
|
85
|
+
|
|
86
|
+
| Kind | Name | Declaration | Module | Package |
|
|
87
|
+
| ---- | -------------------------- | ------------------------ | ------------------------------- | ------- |
|
|
88
|
+
| `js` | `BlockquoteControllerRxjs` | BlockquoteControllerRxjs | src/BlockquoteControllerRxjs.js | |
|
|
89
|
+
|
|
90
|
+
### `index.js`:
|
|
91
|
+
|
|
92
|
+
#### Exports
|
|
93
|
+
|
|
94
|
+
| Kind | Name | Declaration | Module | Package |
|
|
95
|
+
| ---- | -------------------------- | ------------------------ | --------------------------------- | ------- |
|
|
96
|
+
| `js` | `BlockquoteControllerRxjs` | BlockquoteControllerRxjs | ./src/BlockquoteControllerRxjs.js | |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockquote-web-components/blockquote-controller-rxjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"description": "Webcomponent blockquote-controller-rxjs following open-wc recommendations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lit",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
{
|
|
75
75
|
"files": "*.{scss,css}",
|
|
76
76
|
"options": {
|
|
77
|
+
"printWidth": 280,
|
|
77
78
|
"singleQuote": false
|
|
78
79
|
}
|
|
79
80
|
}
|
|
@@ -83,15 +84,30 @@
|
|
|
83
84
|
"parserOptions": {
|
|
84
85
|
"ecmaVersion": "latest"
|
|
85
86
|
},
|
|
86
|
-
"plugins": [
|
|
87
|
-
"log-filenames"
|
|
88
|
-
],
|
|
89
87
|
"extends": [
|
|
90
|
-
"
|
|
91
|
-
"
|
|
88
|
+
"@open-wc",
|
|
89
|
+
"prettier"
|
|
92
90
|
],
|
|
93
91
|
"rules": {
|
|
94
92
|
"class-methods-use-this": "off",
|
|
93
|
+
"indent": [
|
|
94
|
+
"error",
|
|
95
|
+
2,
|
|
96
|
+
{
|
|
97
|
+
"SwitchCase": 1,
|
|
98
|
+
"ignoredNodes": [
|
|
99
|
+
"PropertyDefinition",
|
|
100
|
+
"TemplateLiteral > *"
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
"no-unused-expressions": [
|
|
105
|
+
"error",
|
|
106
|
+
{
|
|
107
|
+
"allowShortCircuit": true,
|
|
108
|
+
"allowTernary": true
|
|
109
|
+
}
|
|
110
|
+
],
|
|
95
111
|
"object-curly-newline": "off",
|
|
96
112
|
"import/extensions": [
|
|
97
113
|
"error",
|
|
@@ -105,33 +121,37 @@
|
|
|
105
121
|
{
|
|
106
122
|
"devDependencies": [
|
|
107
123
|
"**/test/**/*.{js,ts}",
|
|
108
|
-
"**/*.config.{js,mjs,cjs}",
|
|
109
|
-
"**/*.conf.{js,mjs,cjs}"
|
|
124
|
+
"**/*.config.{js,ts,mjs,cjs}",
|
|
125
|
+
"**/*.conf.{js,ts,mjs,cjs}"
|
|
110
126
|
]
|
|
111
127
|
}
|
|
112
128
|
],
|
|
113
129
|
"import/no-unresolved": "off",
|
|
114
|
-
"import/prefer-default-export": "off"
|
|
130
|
+
"import/prefer-default-export": "off",
|
|
131
|
+
"lit/no-native-attributes": "off"
|
|
115
132
|
}
|
|
116
133
|
},
|
|
117
134
|
"stylelint": {
|
|
118
135
|
"extends": "stylelint-config-standard-scss",
|
|
119
136
|
"rules": {
|
|
120
137
|
"custom-property-pattern": null,
|
|
121
|
-
"max-line-length": null
|
|
138
|
+
"max-line-length": null,
|
|
139
|
+
"no-duplicate-selectors": null,
|
|
140
|
+
"color-function-notation": null,
|
|
141
|
+
"alpha-value-notation": null
|
|
122
142
|
}
|
|
123
143
|
},
|
|
124
144
|
"dependencies": {
|
|
125
|
-
"lit": "^2.0
|
|
126
|
-
"rxjs": "^
|
|
145
|
+
"lit": "^2.8.0",
|
|
146
|
+
"rxjs": "^8.0.0-alpha.12"
|
|
127
147
|
},
|
|
128
148
|
"devDependencies": {
|
|
129
|
-
"@blockquote-web-components/blockquote-base-common-dev-dependencies": "^1.
|
|
130
|
-
"@blockquote-web-components/blockquote-base-embedded-webview": "^1.5.
|
|
149
|
+
"@blockquote-web-components/blockquote-base-common-dev-dependencies": "^1.5.0",
|
|
150
|
+
"@blockquote-web-components/blockquote-base-embedded-webview": "^1.5.3"
|
|
131
151
|
},
|
|
132
152
|
"publishConfig": {
|
|
133
153
|
"access": "public"
|
|
134
154
|
},
|
|
135
155
|
"customElements": "custom-elements.json",
|
|
136
|
-
"gitHead": "
|
|
156
|
+
"gitHead": "1d99c84686394229dadc9d1e19f446588a33c8b6"
|
|
137
157
|
}
|
|
@@ -1,76 +1,73 @@
|
|
|
1
|
-
import { Subject, isObservable } from 'rxjs';
|
|
2
|
-
import { takeUntil } from 'rxjs/operators';
|
|
1
|
+
import { Subject, isObservable, takeUntil } from 'rxjs';
|
|
3
2
|
|
|
4
3
|
const unsubscribe = Symbol('unsubscribe');
|
|
5
4
|
const subscriptions = Symbol('subscriptions');
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- It
|
|
21
|
-
- It
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
*/
|
|
7
|
+
* # BlockquoteControllerRxjs
|
|
8
|
+
*
|
|
9
|
+
* 
|
|
10
|
+
*
|
|
11
|
+
* `BlockquoteControllerRxjs` is a Reactive Controller.
|
|
12
|
+
*
|
|
13
|
+
* - Original idea by [Adrian Fâciu](https://github.com/adrianfaciu/rx-lit)
|
|
14
|
+
* - [observables-litelement](https://adrianfaciu.dev/posts/observables-litelement/)
|
|
15
|
+
*
|
|
16
|
+
* `BlockquoteControllerRxjs` provides a subscribe method to which pass the property we want to
|
|
17
|
+
* assign values to and the Observable we want to subscribe.
|
|
18
|
+
*
|
|
19
|
+
* - It works with [reactive properties](https://lit.dev/docs/components/properties/) and non-reactive properties
|
|
20
|
+
* - It ignores calls on the same property with the same Observable
|
|
21
|
+
* - It unsubscribes from the old observable if called again on the same property with a different Observable
|
|
22
|
+
* - It unsubscribes when the component is removed
|
|
23
|
+
*
|
|
24
|
+
* ## Usage
|
|
25
|
+
*
|
|
26
|
+
* ```js
|
|
27
|
+
* class BlockquoteControllerRxjsDemo extends LitElement {
|
|
28
|
+
* static get is() {
|
|
29
|
+
* return 'blockquote-controller-rxjs-demo';
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* static get properties() {
|
|
33
|
+
* return {
|
|
34
|
+
* _pos: {
|
|
35
|
+
* type: Object,
|
|
36
|
+
* attribute: false,
|
|
37
|
+
* },
|
|
38
|
+
* };
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* constructor() {
|
|
42
|
+
* super();
|
|
43
|
+
* this.rx = new BlockquoteControllerRxjs(this);
|
|
44
|
+
* this._pos = { x: 0, y: 0 };
|
|
45
|
+
* this.values$ = fromEvent(window, 'mousemove').pipe(
|
|
46
|
+
* map(({ clientX, clientY }) => ({ x: clientX, y: clientY })),
|
|
47
|
+
* );
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* connectedCallback() {
|
|
51
|
+
* super.connectedCallback();
|
|
52
|
+
*
|
|
53
|
+
* // Property and Observable.
|
|
54
|
+
* this.rx.subscribe('_pos', this.values$);
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* render() {
|
|
58
|
+
* return html`
|
|
59
|
+
* <p>The mouse is at:</p>
|
|
60
|
+
* <pre>
|
|
61
|
+
* x: ${this._pos.x}
|
|
62
|
+
* y: ${this._pos.y}
|
|
63
|
+
* </pre
|
|
64
|
+
* >
|
|
65
|
+
* `;
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
74
71
|
export class BlockquoteControllerRxjs {
|
|
75
72
|
constructor(host) {
|
|
76
73
|
this[unsubscribe] = new Subject();
|
|
@@ -82,7 +79,9 @@ export class BlockquoteControllerRxjs {
|
|
|
82
79
|
if (!isObservable(stream$)) {
|
|
83
80
|
throw new Error('Invalid Observable!');
|
|
84
81
|
}
|
|
82
|
+
|
|
85
83
|
const existingSubscription = this[subscriptions].get(propKey);
|
|
84
|
+
|
|
86
85
|
if (existingSubscription) {
|
|
87
86
|
if (existingSubscription?.stream$ === stream$) {
|
|
88
87
|
return stream$;
|
|
@@ -90,9 +89,7 @@ export class BlockquoteControllerRxjs {
|
|
|
90
89
|
existingSubscription?.subscription?.unsubscribe();
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
// eslint-disable-next-line arrow-parens
|
|
94
92
|
const subscription = stream$.pipe(takeUntil(this[unsubscribe])).subscribe(state => {
|
|
95
|
-
// eslint-disable-next-line no-unused-expressions
|
|
96
93
|
propKey in this.host && (this.host[propKey] = state);
|
|
97
94
|
this.host.requestUpdate();
|
|
98
95
|
});
|
package/README.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
# BlockquoteControllerRxjs
|
|
3
|
-
|
|
4
|
-

|
|
5
|
-
|
|
6
|
-
`BlockquoteControllerRxjs` is a Reactive Controller.
|
|
7
|
-
|
|
8
|
-
- Original idea by [Adrian Fâciu](https://github.com/adrianfaciu/rx-lit)
|
|
9
|
-
- [observables-litelement](https://adrianfaciu.dev/posts/observables-litelement/)
|
|
10
|
-
|
|
11
|
-
`BlockquoteControllerRxjs` provides a subscribe method to which pass the property we want to
|
|
12
|
-
assign values to and the Observable we want to subscribe.
|
|
13
|
-
|
|
14
|
-
- It works with [reactive properties](https://lit.dev/docs/components/properties/) and no-reactive properties
|
|
15
|
-
- It ignores calls on the same property with the same Observable
|
|
16
|
-
- It unsubscribes from old observable if called again on the same property with different Observable
|
|
17
|
-
- It unsubscribes when the component is removed
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
class BlockquoteControllerRxjsDemo extends LitElement {
|
|
23
|
-
static get is() {
|
|
24
|
-
return 'blockquote-controller-rxjs-demo';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static get properties() {
|
|
28
|
-
return {
|
|
29
|
-
_pos: {
|
|
30
|
-
type: Object,
|
|
31
|
-
attribute: false,
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
constructor() {
|
|
37
|
-
super();
|
|
38
|
-
this.rx = new BlockquoteControllerRxjs(this);
|
|
39
|
-
this._pos = { x: 0, y: 0 };
|
|
40
|
-
this.values$ = fromEvent(window, 'mousemove').pipe(
|
|
41
|
-
map(({ clientX, clientY }) => ({ x: clientX, y: clientY })),
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
connectedCallback() {
|
|
46
|
-
super.connectedCallback();
|
|
47
|
-
|
|
48
|
-
// Property and Observable.
|
|
49
|
-
this.rx.subscribe('_pos', this.values$);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
render() {
|
|
53
|
-
return html`
|
|
54
|
-
<p>The mouse is at:</p>
|
|
55
|
-
<pre>
|
|
56
|
-
x: ${this._pos.x}
|
|
57
|
-
y: ${this._pos.y}
|
|
58
|
-
</pre
|
|
59
|
-
>
|
|
60
|
-
`;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Exports
|
|
66
|
-
|
|
67
|
-
- BlockquoteControllerRxjs
|
|
68
|
-
|
|
69
|
-
@tagname blockquote-controller-rxjs
|
|
70
|
-
@element blockquote-controller-rxjs
|
|
71
|
-
*/
|
|
72
|
-
export class ReadmElement extends HTMLElement {}
|