Skip to content

Commit

Permalink
Merge 3f62708 into d072a74
Browse files Browse the repository at this point in the history
  • Loading branch information
myty committed Sep 24, 2022
2 parents d072a74 + 3f62708 commit b07cc0f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: refresh badges
uses: b3b00/refreshBadgesAction@v1.0.7
with:
repository: "myty/composable-promise"
repository: "myty/promise-chain"
branch: main

- uses: actions/setup-node@v2
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Composable-Promise
# PromiseChain

[![GitHub version](https://badgen.net/github/release/myty/composable-promise?color=green)](https://github.com/myty/composable-promise)
[![deno land](https://badgen.net/github/release/myty/composable-promise?color=green&label=deno.land)](https://deno.land/x/composable_promise)
[![npm version](https://badgen.net/npm/v/composable-promise?color=green)](https://www.npmjs.com/package/composable-promise)
[![Coverage Status](https://badgen.net/coveralls/c/github/myty/composable-promise?color=green)](https://coveralls.io/github/myty/composable-promise?branch=main)
[![GitHub version](https://badgen.net/github/release/myty/promise-chain?color=green)](https://github.com/myty/promise-chain)
[![deno land](https://badgen.net/github/release/myty/promise-chain?color=green&label=deno.land)](https://deno.land/x/promise_chain)
[![npm version](https://badgen.net/npm/v/promise-chain?color=green)](https://www.npmjs.com/package/promise-chain)
[![Coverage Status](https://badgen.net/coveralls/c/github/myty/promise-chain?color=green)](https://coveralls.io/github/myty/promise-chain?branch=main)

Wrapper utility class that enables composition via asynchronous (Promises) and
synchronous method chaining.
Expand All @@ -14,17 +14,17 @@ synchronous method chaining.

```bash
# npm
npm install --save composable-promise
npm install --save promise-chain
# yarn
yarn add composable-promise
yarn add promise-chain
# pnpm
pnpm install --save composable-promise
pnpm install --save promise-chain
```

### Deno

```bash
import { Composable } from "https://deno.land/x/composable_promise/mod.ts";
import { Composable } from "https://deno.land/x/promise_chain/mod.ts";
```
## Example Usage
Expand Down Expand Up @@ -78,7 +78,7 @@ console.log(`Result: propertyOne=${propertyOne}, propertyTwo=${propertyTwo}`);
// OUTPUT: "Result: propertyOne=3, propertyTwo=10"
```
With Composable-Promise, it is simplified and easier to read.
With PromiseChain, it is simplified and easier to read.
```typescript
const { propertyOne, propertyTwo } = await Composable.create(testClass)
Expand Down
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Composable } from "./composable.ts";
export { PromiseChain } from "./promise-chain.ts";
8 changes: 4 additions & 4 deletions composable_bench.ts → promise-chain.bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Composable } from "./composable.ts";
import { PromiseChain } from "./promise-chain.ts";
import { TestClass } from "./stubs/test-class.ts";

const iterate = (
Expand All @@ -18,7 +18,7 @@ Deno.bench(
Deno.bench(
"Composable Async Chain (1 Step)",
{ group: "1 step" },
iterate((t) => Composable.create(t).asyncIncrement("propertyOne", 3)),
iterate((t) => PromiseChain.create(t).asyncIncrement("propertyOne", 3)),
);

Deno.bench(
Expand All @@ -35,7 +35,7 @@ Deno.bench(
"Composable Async Chain (2 Steps)",
{ group: "2 steps" },
iterate((t) =>
Composable.create(t).asyncIncrement("propertyOne", 3).increment(
PromiseChain.create(t).asyncIncrement("propertyOne", 3).increment(
"propertyTwo",
5,
)
Expand All @@ -60,7 +60,7 @@ Deno.bench(
"Composable Async Chain (6 Steps)",
{ group: "6 steps" },
iterate((t) =>
Composable.create(t)
PromiseChain.create(t)
.asyncIncrement("propertyOne", 3)
.asyncIncrementTwo()
.asyncIncrementOne()
Expand Down
10 changes: 5 additions & 5 deletions composable_test.ts → promise-chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
assert,
assertEquals,
} from "https://deno.land/std@0.154.0/testing/asserts.ts";
import { Composable } from "./composable.ts";
import { PromiseChain } from "./promise-chain.ts";
import { TestClass } from "./stubs/test-class.ts";

Deno.test(async function whenTraditionalAsyncChainingItReturnsResult() {
Expand All @@ -28,7 +28,7 @@ Deno.test(async function whenAsyncChainingItReturnsResult() {
const testClass = new TestClass();

// Act
const result = await Composable.create(testClass)
const result = await PromiseChain.create(testClass)
.asyncIncrement("propertyOne", 3)
.asyncIncrementTwo()
.asyncIncrementOne()
Expand All @@ -46,18 +46,18 @@ Deno.test(function whenComposableAsyncItIsPromise() {
const testClass = new TestClass();

// Act
const result = Composable.create(testClass);
const result = PromiseChain.create(testClass);

// Assert
assert(result instanceof Composable);
assert(result instanceof PromiseChain);
assert(result instanceof Promise);
});

Deno.test(async function whenChainedPromiseIsReusedItReturnsCachedResult() {
// Arrange
const testClass = new TestClass();
const durationExpectedMs = 250;
const resultTask = Composable.create(testClass)
const resultTask = PromiseChain.create(testClass)
.asyncIncrement("propertyTwo", 3)
.asyncIncrementOneLongRunningTask(durationExpectedMs);
await resultTask;
Expand Down
6 changes: 3 additions & 3 deletions composable.ts → promise-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { AsyncComposable } from "./types.ts";
* Utility class to wrap a composition class with the intended purpose of chaining methods, specifically useful for
* functions that return Promises. Note: Promise functions and non-promise functions can be mixed.
*/
export class Composable<T> extends Promise<T> implements Promise<T> {
export class PromiseChain<T> extends Promise<T> implements Promise<T> {
/**
* Create a chaninable class based off of the functions that return "this" or a Promise of "this".
*/
static create<T>(wrappedClass: T): AsyncComposable<T> {
return new Composable(wrappedClass) as unknown as AsyncComposable<T>;
return new PromiseChain(wrappedClass) as unknown as AsyncComposable<T>;
}

private _valuePromise: Promise<T>;
Expand All @@ -22,7 +22,7 @@ export class Composable<T> extends Promise<T> implements Promise<T> {
this.catch = (...args) => this._valuePromise.catch(...args);
this.finally = (...args) => this._valuePromise.finally(...args);

Composable.keysOfObject(_wrappedClass).forEach((key) => {
PromiseChain.keysOfObject(_wrappedClass).forEach((key) => {
const callableFunc = _wrappedClass[key];

if (!(callableFunc instanceof Function)) {
Expand Down
6 changes: 3 additions & 3 deletions scripts/build_npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ await build({
deno: "dev",
},
package: {
name: "composable-promise",
name: "promise-chain",
version: Deno.args[0].substring("refs/tags/v".length),
description:
"Wrapper utility class that enables composition via asynchronous (Promises) and synchronous method chaining.",
license: "MIT",
repository: {
type: "git",
url: "git+https://github.com/myty/composable-promise.git",
url: "git+https://github.com/myty/promise-chain.git",
},
bugs: {
url: "https://github.com/myty/composable-promise/issues",
url: "https://github.com/myty/promise-chain/issues",
},
},
});
Expand Down

0 comments on commit b07cc0f

Please sign in to comment.