Skip to content

Commit fb1453d

Browse files
Merge pull request #2 from angular-package/1.0.x
1.0.0
2 parents df26ef4 + f8bd0e1 commit fb1453d

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

README.md

+15-17
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ Manages the callback [`function`][js-function] of a [`ResultCallback`](#resultca
139139

140140
**Instance methods:**
141141

142-
| Callback.prototype. | Description |
143-
| :------------------------------------------------ | :---------- |
144-
| [`getCallback()`][callback-getcallback] | Gets from the storage specified by-name callback [`function`][js-function] of a [`ResultCallback`](#resultcallback) type |
145-
| [`setErrorCallback()`][callback-seterrorcallback] | Sets a callback [`function`][js-function] of a [`ResultCallback`](#resultcallback) type that throws [`ValidationError`][error-validationerror] with a specified message on a state from the provided `throwOnState` to the storage under the given allowed name restricted by `AllowNames` |
146-
| [`setResultCallback()`][callback-setcallback] | Sets a callback of a [`ResultCallback`](#resultcallback) type to the storage under the given allowed `name`, which is restricted by `AllowNames` |
142+
| Callback.prototype. | Description |
143+
| :-------------------------------------------------- | :---------- |
144+
| [`getCallback()`][callback-getcallback] | Gets from the storage specified by-name callback [`function`][js-function] of a [`ResultCallback`](#resultcallback) type |
145+
| [`setErrorCallback()`][callback-seterrorcallback] | Sets a callback [`function`][js-function] of a [`ResultCallback`](#resultcallback) type that throws [`ValidationError`][error-validationerror] with a specified message on a state from the provided `throwOnState` to the storage under the given allowed name restricted by `AllowNames` |
146+
| [`setResultCallback()`][callback-setresultcallback] | Sets a callback of a [`ResultCallback`](#resultcallback) type to the storage under the given allowed `name`, which is restricted by `AllowNames` |
147147

148148
[callback-getcallback]: #callbackprototypegetcallback
149-
[callback-setcallback]: #callbackprototypesetcallback
150149
[callback-seterrorcallback]: #callbackprototypeseterrorcallback
150+
[callback-setresultcallback]: #callbackprototypesetresultcallback
151151

152152
<br>
153153

@@ -177,13 +177,13 @@ static defineResultCallback<Payload extends object>(
177177

178178
| Name | Description |
179179
| :----------------------- | :---------- |
180-
| `Payload extends object` | A generic `Payload` variable that is constrained by the [`object`][js-object] type, is used by the type of `resultHandler` parameter and is linked with the return type `ResultCallback<Payload>`. Its value can be captured from the provided `capturePayload` optional parameter |
180+
| `Payload extends object` | The shape of the optional payload parameter of the [`ResultCallback`](#resultcallback) and [`ResultHandler`](#resulthandler) function, which is constrained by the [`object`][js-object] type. Its value can be captured from a type of the provided `capturePayload` optional parameter |
181181

182182
**Parameters:**
183183

184184
| Name: type | Description |
185185
| :-------------------------------------- | :---------- |
186-
| `resultHandler: ResultHandler<Payload>` | The [`function`][js-function] of [`ResultHandler`](#resulthandler) type to handle the `result` and optional `payload` of [`ResultCallback`](#resultcallback) function |
186+
| `resultHandler: ResultHandler<Payload>` | The [`function`][js-function] that is guarded by the [`ResultHandler`](#resulthandler) type to handle the result and optional payload of the [`ResultCallback`](#resultcallback) function |
187187
| `capturePayload?: Payload` | An optional [`object`][js-object] of generic type `Payload` that is used only to capture the value by the generic type variable `Payload` |
188188

189189
**Returns:**
@@ -332,13 +332,13 @@ static guard<Payload extends object>(
332332

333333
| Name: type | Description |
334334
| :---------------------------------------- | :---------- |
335-
| `resultCallback: ResultCallback<Payload>` | The [`function`][js-function] of [`ResultCallback`](#resultcallback) type with the shape of payload from the generic variable `Payload` to guard |
335+
| `resultCallback: ResultCallback<Payload>` | The [`function`][js-function] of [`ResultCallback`](#resultcallback) type with the shape of payload from the generic type variable `Payload` to guard |
336336

337337
**Returns:**
338338

339339
| Returns | Type | Description |
340340
| :------------------------------------------ | :-------: | :----------- |
341-
| `resultCallback is ResultCallback<Payload>` | `boolean` | The **return type** is [`boolean`][js-boolean] as the result of its statement that indicates the provided `resultCallback` is a [`function`][js-function] of a [`ResultCallback`](#resultcallback) type with the shape of payload from the generic variable `Payload` |
341+
| `resultCallback is ResultCallback<Payload>` | `boolean` | The **return type** is [`boolean`][js-boolean] as the result of its statement that indicates the provided `resultCallback` is a [`function`][js-function] of a [`ResultCallback`](#resultcallback) type with the shape of payload from the generic type variable `Payload` |
342342

343343
The **return value** is a `boolean` indicating whether the provided `resultCallback` parameter is a [`function`][js-function].
344344

@@ -371,7 +371,7 @@ static isCallback<AllowNames extends string>(
371371

372372
| Name | Description |
373373
| :-------------------------- | :---------- |
374-
| `AllowNames extends string` | An optional generic variable of `AllowNames` name that is constrained by the [`string`][js-string] type and is used to indicate allowed names under which callback functions can be stored for the return type `value is Callback<AllowNames>`. Its value can be captured from the provided `allowNames` rest parameter |
374+
| `AllowNames extends string` | An optional generic type variable of `AllowNames` name that is constrained by the [`string`][js-string] type and is used to indicate allowed names under which callback functions can be stored for the return type `value is Callback<AllowNames>`. Its value can be captured from the provided `allowNames` rest parameter |
375375

376376
**Parameters:**
377377

@@ -384,7 +384,7 @@ static isCallback<AllowNames extends string>(
384384

385385
| Returns | Type | Description |
386386
| :------------------------------ | :-------: | :---------- |
387-
| `value is Callback<AllowNames>` | `boolean` | The **return type** is `boolean` as the result of its statement that indicates the provided `value` is a [`Callback`](#callback) with allowed names from the provided `allowNames` parameter or generic variable `AllowNames` |
387+
| `value is Callback<AllowNames>` | `boolean` | The **return type** is `boolean` as the result of its statement that indicates the provided `value` is a [`Callback`](#callback) with allowed names from the provided `allowNames` parameter or generic type variable `AllowNames` |
388388

389389
The **return value** is a `boolean` indicating whether the `value` is an instance of [`Callback`](#callback) .
390390

@@ -428,7 +428,7 @@ new Callback<AllowNames extends string>(...allowNames: AllowNames[]) {
428428

429429
| Name | Description |
430430
| :---------------------------- | :---------- |
431-
| `AllowedNames extends string` | A generic variable `AllowNames` that is constrained by the [`string`][js-string] type and is used to **restrict** allowed names under which callback functions can be stored. By default, its value is captured from the provided `allowNames` rest parameter |
431+
| `AllowedNames extends string` | A generic type variable `AllowNames` that is constrained by the [`string`][js-string] type and is used to **restrict** allowed names under which callback functions can be stored. By default, its value is captured from the provided `allowNames` rest parameter |
432432

433433
**Parameters:**
434434

@@ -511,7 +511,7 @@ callback
511511
```
512512

513513
```typescript
514-
// Generic variable payload example usage.
514+
// Generic type variable payload example usage.
515515
import { Callback } from '@angular-package/callback';
516516
/**
517517
* Initialize `Callback`.
@@ -804,7 +804,7 @@ firstNameCallback(false, { id: 5, name: 'there is no name' });
804804

805805
#### `CallbackPayload`
806806

807-
807+
![experimental]
808808

809809
Experimental shape for a generic type variable `Payload`.
810810

@@ -887,8 +887,6 @@ isString('it is a string', (result: boolean, payload) => {
887887

888888
#### `ResultCallback`
889889

890-
![experimental]
891-
892890
Represents a callback function with parameters, a `result` of a [`boolean`][js-boolean] type, and an optional `payload` of a generic type `Payload`.
893891

894892
```typescript

src/lib/callback.class.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export class Callback<AllowNames extends string> {
3131
/**
3232
* Defines the `function` of `ResultCallback` type that contains a `ResultHandler` function to handle the `result` and optional
3333
* `payload`.
34-
* @param resultHandler The function of `ResultHandler` type to handle the `result` and optional `payload` of `ResultCallback` function.
34+
* @var Payload The shape of the optional payload parameter of the `ResultCallback` and `ResultHandler` function, which is constrained by
35+
* the `object` type. Its value can be captured from a type of the provided `capturePayload` optional parameter.
36+
* @param resultHandler The `function` that is guarded by the `ResultHandler` type to handle the result and optional payload of the
37+
* `ResultCallback` function.
3538
* @param capturePayload An optional `object` of generic type `Payload` that is used only to capture the value by the generic type
3639
* variable `Payload`.
3740
* @returns The return value is a function of a `ResultCallback` type that contains a function that handles its result.
@@ -99,7 +102,6 @@ export class Callback<AllowNames extends string> {
99102
//#endregion
100103

101104
/**
102-
* Manages the callback function of a `ResultCallback` type.
103105
* Initialize an instance of a `Callback` with the allowed names under which callback functions can be stored.
104106
* @param allowNames A rest parameter of allowed names of a `string` type, under which callback functions can be stored.
105107
*/

src/test/callback.spec.ts

+16-15
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,6 @@ testing.describe(Callback.name, () => {
167167
});
168168

169169
//#region Callback public methods
170-
testing.describe(`.prototype.setCallback()`, () => {
171-
testing.it(
172-
'should properly sets the callback function under the `setCallback` name',
173-
() => {
174-
toBe.undefined(callback.getCallback('setCallback'));
175-
callback.setResultCallback('setCallback', (result: boolean, value: any) => {
176-
if (is.false(result)) {
177-
throw new ValidationError('The given value must be a string type');
178-
}
179-
});
180-
toBe.function(callback.getCallback('setCallback'));
181-
}
182-
);
183-
});
184-
185170
testing.describe(`.prototype.getCallback()`, () => {
186171
try {
187172
is.string(5, callback.getCallback('setCallback'));
@@ -234,5 +219,21 @@ testing.describe(Callback.name, () => {
234219
}
235220
});
236221
});
222+
223+
testing.describe(`.prototype.setResultCallback()`, () => {
224+
testing.it(
225+
'should properly sets the callback function under the `setCallback` name',
226+
() => {
227+
toBe.undefined(callback.getCallback('setCallback'));
228+
callback.setResultCallback('setCallback', (result: boolean, value: any) => {
229+
if (is.false(result)) {
230+
throw new ValidationError('The given value must be a string type');
231+
}
232+
});
233+
toBe.function(callback.getCallback('setCallback'));
234+
}
235+
);
236+
});
237+
237238
//#endregion
238239
});

0 commit comments

Comments
 (0)