Skip to content

Commit cf58d8c

Browse files
updated version
1 parent 04a09bc commit cf58d8c

3 files changed

Lines changed: 67 additions & 66 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cosmicmind/patternjs",
3-
"version": "0.0.1-rc-011825-3",
3+
"version": "0.0.1-rc-022525-3",
44
"description": "A library of Design Patterns in TypeScript.",
55
"keywords": ["typescript", "design-patterns", "library", "cosmicmind", "patternjs"],
66
"author": {

src/behavioral/RequestChain.ts

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -39,94 +39,96 @@ import {
3939
} from '@cosmicmind/foundationjs'
4040

4141
export type Chainable<T> = {
42-
/**
43-
* Retrieves the next value in the chain.
44-
*
45-
* @return {Optional<Chainable<T>>} The next value in the chain, or undefined if there is none.
46-
*/
47-
get next(): Optional<Chainable<T>>
48-
49-
/**
50-
* Executes the method with the given arguments.
51-
*
52-
* @param {...T} args - The arguments to be passed to the method.
53-
* @return {void}
54-
*/
55-
execute(...args: T[]): void
56-
57-
/**
58-
* Checks if the given arguments can be processed.
59-
*
60-
* @param {...T} args - The arguments to be checked.
61-
* @return {void}
62-
*/
63-
isProcessable(...args: T[]): void
42+
/**
43+
* Retrieves the next value in the chain.
44+
*
45+
* @return {Optional<Chainable<T>>} The next value in the chain, or undefined if there is none.
46+
*/
47+
get next(): Optional<Chainable<T>>
48+
49+
/**
50+
* Executes the method with the given arguments.
51+
*
52+
* @param {...T} args - The arguments to be passed to the method.
53+
* @return {boolean}
54+
*/
55+
execute(...args: T[]): boolean
56+
57+
/**
58+
* Checks if the given arguments can be processed.
59+
*
60+
* @param {...T} args - The arguments to be checked.
61+
* @return {boolean}
62+
*/
63+
isProcessable(...args: T[]): boolean
6464
}
6565

6666
export abstract class RequestChain<T> implements Chainable<T> {
6767
protected _next: Optional<Chainable<T>>
6868

6969
/**
70-
* Retrieves the next item in the chain.
71-
*
72-
* @returns {Optional<Chainable<T>>} The next item in the chain, or undefined if there isn't a next item.
73-
*/
70+
* Retrieves the next item in the chain.
71+
*
72+
* @returns {Optional<Chainable<T>>} The next item in the chain, or undefined if there isn't a next item.
73+
*/
7474
get next(): Optional<Chainable<T>> {
7575
return this._next
7676
}
7777

7878
/**
79-
* Appends a chainable object to the current object.
80-
*
81-
* @param {Chainable<T>} chainable - The chainable object to append.
82-
* @return {void} - This method does not return anything.
83-
*/
79+
* Appends a chainable object to the current object.
80+
*
81+
* @param {Chainable<T>} chainable - The chainable object to append.
82+
* @return {void} - This method does not return anything.
83+
*/
8484
append(chainable: Chainable<T>): void {
8585
this._next = chainable
8686
}
8787

8888
/**
89-
* Clears the next reference of the object.
90-
*
91-
* @returns {void}
92-
*/
89+
* Clears the next reference of the object.
90+
*
91+
* @returns {void}
92+
*/
9393
clear(): void {
9494
this._next = undefined
9595
}
9696

9797
/**
98-
* Executes the processor if the given arguments are executable,
99-
* otherwise passes the arguments to the next execute method in the chain.
100-
*
101-
* @template T - Type of the arguments.
102-
*
103-
* @param {...T[]} args - The arguments to be passed to the processor.
104-
*
105-
* @returns {void}
106-
*/
107-
execute(...args: T[]): void {
98+
* Executes the processor if the given arguments are executable,
99+
* otherwise passes the arguments to the next execute method in the chain.
100+
*
101+
* @template T - Type of the arguments.
102+
*
103+
* @param {...T[]} args - The arguments to be passed to the processor.
104+
*
105+
* @returns {boolean}
106+
*/
107+
execute(...args: T[]): boolean {
108108
if (this.isProcessable(...args)) {
109-
this.processor(...args)
110-
} else {
111-
this.next?.execute(...args)
109+
return this.processor(...args)
110+
} else if (this.next?.execute(...args)) {
111+
return true
112112
}
113+
114+
return false
113115
}
114116

115-
/**
116-
* Determines if the given arguments are processable.
117-
*
118-
* @param {...T} args - The arguments to be checked for processability.
119-
* @return {boolean} - True if the arguments are processable, false otherwise.
120-
*/
121-
abstract isProcessable(...args: T[]): boolean
122-
123-
/**
124-
* Process the given arguments of type T.
125-
*
126-
* @param {...T} args - The arguments to be processed.
127-
* @return {void}
128-
*/
129-
protected abstract processor(...args: T[]): void
117+
/**
118+
* Determines if the given arguments are processable.
119+
*
120+
* @param {...T} args - The arguments to be checked for processability.
121+
* @return {boolean} - True if the arguments are processable, false otherwise.
122+
*/
123+
abstract isProcessable(...args: T[]): boolean
124+
125+
/**
126+
* Process the given arguments of type T.
127+
*
128+
* @param {...T} args - The arguments to be processed.
129+
* @return {boolean}
130+
*/
131+
protected abstract processor(...args: T[]): boolean
130132
}
131133

132134
/**

vite.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
*/
3232

33-
34-
3533
import {
3634
URL,
3735
fileURLToPath,
@@ -44,6 +42,7 @@ import {
4442
defineConfig,
4543
UserConfigExport,
4644
} from 'vite'
45+
4746
import dts from 'vite-plugin-dts'
4847

4948
export default ({ mode }: ConfigEnv): UserConfigExport => {

0 commit comments

Comments
 (0)