@@ -39,94 +39,96 @@ import {
3939} from '@cosmicmind/foundationjs'
4040
4141export 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
6666export 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/**
0 commit comments