5htp-core 0.6.3-1 → 0.6.3-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -102,51 +102,34 @@ export default class ApiClient implements ApiClientService {
102
102
  ----------------------------------*/
103
103
  public createFetcher<TData extends unknown = unknown>(...args: TFetcherArgs): TFetcher<TData> {
104
104
  const [method, path, data, options] = args;
105
- return {
105
+
106
+ // Lazily create (and cache) the underlying promise so the fetcher behaves like a real promise instance.
107
+ let promise: Promise<TData> | undefined;
108
+
109
+ const fetcher = {
106
110
  method, path, data, options,
111
+ } as TFetcher<TData>;
112
+
113
+ const getPromise = () => {
114
+ if (!promise)
115
+ promise = this.fetchAsync<TData>(fetcher.method, fetcher.path, fetcher.data, fetcher.options);
107
116
 
108
- // For async calls: api.post(...).then((data) => ...)
109
- then: (callback: (data: any) => void) => this.fetchAsync<TData>(...args)
110
- .then(callback)
111
- .catch( e => {
112
- this.app.handleError(e);
113
-
114
- // Don't run what is next
115
- return {
116
- then: () => {},
117
- catch: () => {},
118
- finally: (callback: () => void) => {
119
- callback();
120
- },
121
- }
122
- }),
123
-
124
- // Default error behavior only if not handled before by the app
125
- catch: (callback: (data: any) => false | void) => this.fetchAsync<TData>(...args)
126
- .catch((e) => {
127
-
128
- const shouldThrow = callback(e);
129
- if (shouldThrow)
130
- this.app.handleError(e);
131
-
132
- // Don't run what is next
133
- return {
134
- then: () => {},
135
- catch: () => {},
136
- finally: (callback: () => void) => {
137
- callback();
138
- },
139
- }
140
-
141
- }),
142
-
143
- finally: (callback: () => void) => this.fetchAsync<TData>(...args)
144
- .finally(callback)
145
- .catch( e => this.app.handleError(e)),
146
-
147
- run: () => this.fetchAsync<TData>(...args)
148
- .catch( e => this.app.handleError(e)),
117
+ return promise;
149
118
  };
119
+
120
+ // For async calls: api.post(...).then((data) => ...)
121
+ fetcher.then = (onfulfilled?: any, onrejected?: any) =>
122
+ getPromise().then(onfulfilled, onrejected) as any;
123
+
124
+ fetcher.catch = (onrejected?: any) =>
125
+ getPromise().catch(onrejected) as any;
126
+
127
+ fetcher.finally = (onfinally?: any) =>
128
+ getPromise().finally(onfinally) as any;
129
+
130
+ fetcher.run = () => getPromise();
131
+
132
+ return fetcher;
150
133
  }
151
134
 
152
135
  public async fetchAsync<TData extends unknown = unknown>(...[
@@ -281,4 +264,4 @@ export default class ApiClient implements ApiClientService {
281
264
  });
282
265
  }
283
266
 
284
- }
267
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "5htp-core",
3
3
  "description": "Convenient TypeScript framework designed for Performance and Productivity.",
4
- "version": "0.6.3-1",
4
+ "version": "0.6.3-2",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp-core.git",
7
7
  "license": "MIT",
package/types/icons.d.ts CHANGED
@@ -1 +1 @@
1
- export type TIcones = "solid/spinner-third"|"rocket"|"user-circle"|"search"|"long-arrow-right"|"lightbulb"|"long-arrow-left"|"magnet"|"at"|"phone"|"brands/linkedin"|"arrow-right"|"times"|"star"|"plus"|"minus"|"trash"|"paper-plane"|"play"|"stop"|"plus-circle"|"clock"|"cog"|"ellipsis-h"|"regular/shield-check"|"angle-down"|"check"|"angle-up"|"plane-departure"|"comments-alt"|"user-shield"|"shield-alt"|"chart-line"|"money-bill-wave"|"link"|"file-alt"|"solid/crown"|"eye"|"pen"|"file"|"user-plus"|"sack-dollar"|"info-circle"|"mouse-pointer"|"thumbs-up"|"dollar-sign"|"envelope"|"download"|"brands/google"|"brands/whatsapp"|"crown"|"check-circle"|"exclamation-circle"|"times-circle"|"arrow-left"|"key"|"broom"|"angle-left"|"angle-right"|"solid/check-circle"|"solid/exclamation-triangle"|"solid/times-circle"|"hourglass"|"building"|"briefcase"|"map-marker-alt"|"graduation-cap"|"coins"|"plug"|"coin"|"question-circle"|"arrow-to-bottom"|"external-link"|"minus-circle"|"magic"|"user"|"meh-rolling-eyes"|"unlink"|"bold"|"italic"|"underline"|"strikethrough"|"subscript"|"superscript"|"code"|"font"|"empty-set"|"horizontal-rule"|"page-break"|"image"|"table"|"poll"|"columns"|"sticky-note"|"caret-right"|"list-ul"|"check-square"|"h1"|"h2"|"h3"|"h4"|"list-ol"|"paragraph"|"quote-left"|"align-left"|"align-center"|"align-right"|"align-justify"|"indent"|"outdent"
1
+ export type TIcones = "solid/spinner-third"|"times"|"at"|"star"|"plus"|"minus"|"trash"|"user-circle"|"search"|"long-arrow-right"|"lightbulb"|"long-arrow-left"|"magnet"|"phone"|"brands/linkedin"|"arrow-right"|"plane-departure"|"plus-circle"|"comments-alt"|"rocket"|"user-shield"|"shield-alt"|"chart-line"|"money-bill-wave"|"link"|"file-alt"|"paper-plane"|"solid/crown"|"eye"|"pen"|"file"|"angle-up"|"angle-down"|"envelope"|"play"|"stop"|"clock"|"cog"|"ellipsis-h"|"check"|"user-plus"|"sack-dollar"|"info-circle"|"mouse-pointer"|"thumbs-up"|"dollar-sign"|"regular/shield-check"|"download"|"brands/google"|"brands/whatsapp"|"crown"|"check-circle"|"exclamation-circle"|"times-circle"|"arrow-left"|"key"|"broom"|"arrow-to-bottom"|"minus-circle"|"map-marker-alt"|"solid/check-circle"|"solid/exclamation-triangle"|"solid/times-circle"|"hourglass"|"external-link"|"user"|"building"|"briefcase"|"graduation-cap"|"angle-left"|"angle-right"|"plug"|"magic"|"coins"|"coin"|"question-circle"|"meh-rolling-eyes"|"bold"|"italic"|"underline"|"strikethrough"|"subscript"|"superscript"|"code"|"unlink"|"font"|"empty-set"|"horizontal-rule"|"page-break"|"image"|"table"|"poll"|"columns"|"sticky-note"|"caret-right"|"list-ul"|"check-square"|"h1"|"h2"|"h3"|"h4"|"list-ol"|"paragraph"|"quote-left"|"align-left"|"align-center"|"align-right"|"align-justify"|"indent"|"outdent"