@stoplight/lifecycle

WebJar for @stoplight/lifecycle

License

License

Apache-2.0
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

stoplight__lifecycle
Last Version

Last Version

2.3.2
Release Date

Release Date

Type

Type

jar
Description

Description

@stoplight/lifecycle
WebJar for @stoplight/lifecycle
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/stoplightio/lifecycle

Download stoplight__lifecycle

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/stoplight__lifecycle/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>stoplight__lifecycle</artifactId>
    <version>2.3.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/stoplight__lifecycle/
implementation 'org.webjars.npm:stoplight__lifecycle:2.3.2'
// https://jarcasting.com/artifacts/org.webjars.npm/stoplight__lifecycle/
implementation ("org.webjars.npm:stoplight__lifecycle:2.3.2")
'org.webjars.npm:stoplight__lifecycle:jar:2.3.2'
<dependency org="org.webjars.npm" name="stoplight__lifecycle" rev="2.3.2">
  <artifact name="stoplight__lifecycle" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='stoplight__lifecycle', version='2.3.2')
)
libraryDependencies += "org.webjars.npm" % "stoplight__lifecycle" % "2.3.2"
[org.webjars.npm/stoplight__lifecycle "2.3.2"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : wolfy87-eventemitter jar [5.2.8,5.3)

Project Modules

There are no modules declared in this project.

@stoplight/lifecycle

Maintainability Test Coverage

Event and disposable helpers.

Features

  • Disposable helpers.
  • Event emitter helpers.

Installation

Supported in modern browsers and node.

# latest stable
yarn add @stoplight/lifecycle

Usage

Disposables

A standardized way for things to declare how they cleanup. Simple example below:

import {
  DisposableCollection,
  EventEmitter,
  IDisposable
} from "@stoplight/lifecycle";

export class Editor implements IDisposable {
  // EventEmitter itself is an IDisposable
  public readonly valueEmitter = new EventEmitter<string, "didUpdate">();

  private readonly disposables: DisposableCollection = new DisposableCollection();

  constructor() {
    this.disposables.push(this.valueEmitter);
  }

  // Implement IDisposable
  dispose() {
    this.disposables.dispose();
  }
}

Emitter

A simple example editor that allows users to subscribe to value update events.

import { EventEmitter, IDisposable } from "@stoplight/lifecycle";

class Editor implements IDisposable {
  private _value = "";

  // create an emitter instance for this editor, defining the possible events and event object value
  private valueEmitter = new EventEmitter<string, "willUpdate" | "didUpdate">();

  get value() {
    return this._value;
  }

  set value(val: string) {
    this.valueEmitter.emit("willUpdate", this._value);
    this._value = val;
    this.valueEmitter.emit("didUpdate", this._value);
  }

  get onWillUpdateValue() {
    return this.valueEmitter.on("willUpdate");
  }

  get onDidUpdateValue() {
    return this.valueEmitter.on("didUpdate");
  }

  dispose() {
    // best practice to cleanup the emitter
    this.valueEmitter.dispose();
  }
}

const editor = new Editor();

const willUpdateListener = editor.onWillUpdateValue(val => {
  console.log("next value: ", val);
});

const didUpdateListener = editor.onDidUpdateValue(val => {
  console.log("new value: ", val);
});

// stop listening to willUpdate event
willUpdateListener.dispose();

Contributing

  1. Clone repo.
  2. Create / checkout feature/{name}, chore/{name}, or fix/{name} branch.
  3. Install deps: yarn.
  4. Make your changes.
  5. Run tests: yarn test.prod.
  6. Stage relevant files to git.
  7. Commit: yarn commit. NOTE: Commits that don't follow the conventional format will be rejected. yarn commit creates this format for you, or you can put it together manually and then do a regular git commit.
  8. Push: git push.
  9. Open PR targeting the next branch.
org.webjars.npm

Stoplight

Stoplight leverages your OpenAPI documents to drive the entire API development process

Versions

Version
2.3.2