1.3.0 • Published 2 months ago

@blockquote-web-components/blockquote-controller-rxjs v1.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

BlockquoteControllerRxjs

Lit

BlockquoteControllerRxjs is a Reactive Controller.

BlockquoteControllerRxjs provides a subscribe method to which pass the property we want to assign values to and the Observable we want to subscribe.

  • It works with reactive properties and non-reactive properties
  • It ignores calls on the same property with the same Observable
  • It unsubscribes from the old observable if called again on the same property with a different Observable
  • It unsubscribes when the component is removed

Demo

Open in StackBlitz

Usage

class BlockquoteControllerRxjsDemo extends LitElement {
  static get is() {
    return 'blockquote-controller-rxjs-demo';
  }

  static get properties() {
    return {
      _pos: {
        type: Object,
        attribute: false,
      },
    };
  }

  constructor() {
    super();
    this.rx = new BlockquoteControllerRxjs(this);
    this._pos = { x: 0, y: 0 };
    this.values$ = fromEvent(window, 'mousemove').pipe(
      map(({ clientX, clientY }) => ({ x: clientX, y: clientY })),
    );
  }

  connectedCallback() {
    super.connectedCallback();

    // Property and Observable.
    this.rx.subscribe('_pos', this.values$);
  }

  render() {
    return html`
      <p>The mouse is at:</p>
      <pre>
        x: ${this._pos.x}
        y: ${this._pos.y}
      </pre
      >
    `;
  }
}

src/BlockquoteControllerRxjs.js:

class: BlockquoteControllerRxjs

Fields
NamePrivacyTypeDefaultDescriptionInherited From
new Map()
Methods
NamePrivacyDescriptionParametersReturnInherited From
subscribepropKey, stream$
hostDisconnected

Exports

KindNameDeclarationModulePackage
jsBlockquoteControllerRxjsBlockquoteControllerRxjssrc/BlockquoteControllerRxjs.js

src/index.js:

Exports

KindNameDeclarationModulePackage
jsBlockquoteControllerRxjsBlockquoteControllerRxjs./BlockquoteControllerRxjs.js
1.3.0

2 months ago

1.2.0

2 months ago

1.1.8

4 months ago

1.1.7

4 months ago

1.1.6

4 months ago

1.1.5

4 months ago

1.1.4

4 months ago

1.1.3

5 months ago

1.1.1

6 months ago

1.1.2

6 months ago

1.0.19

11 months ago

1.1.0

6 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.22

10 months ago

1.0.21

11 months ago

1.0.20

11 months ago

1.0.24

7 months ago

1.0.23

9 months ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.9

2 years ago

1.0.11

1 year ago

1.0.10

2 years ago

1.0.12

1 year ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago