@cocreate/lazy-loader 1.20.5 → 1.21.0

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.21.0](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.20.5...v1.21.0) (2024-08-30)
2
+
3
+
4
+ ### Features
5
+
6
+ * handle nested initailization function ([c46b449](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/c46b4497936e61d4c932de664be70bbbf6e72f05))
7
+
1
8
  ## [1.20.5](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.20.4...v1.20.5) (2024-08-24)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/lazy-loader",
3
- "version": "1.20.5",
3
+ "version": "1.21.0",
4
4
  "description": "A simple lazy-loader component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "lazy-loader",
package/src/server.js CHANGED
@@ -193,12 +193,22 @@ class CoCreateLazyLoader {
193
193
  throw new Error(`Missing ${name} key in organization apis object`);
194
194
 
195
195
  // ToDo: if data.endpoint service not required as endpoint will be used
196
- const service = require(config.path);
197
- let instance
198
- if (config.initialize)
199
- instance = new service[config.initialize](key);
200
- else
201
- instance = new service(key);
196
+ let instance = require(config.path);
197
+
198
+ if (config.initialize) {
199
+ const initialize = config.initialize.split('.');
200
+
201
+ // Traverse the nested structure to reach the correct constructor
202
+ for (let i = 0; i < initialize.length; i++) {
203
+ if (instance[initialize[i]]) {
204
+ instance = instance[initialize[i]];
205
+ } else {
206
+ throw new Error(`Service path ${config.initialize} is incorrect at ${initialize[i]}`);
207
+ }
208
+ }
209
+ }
210
+
211
+ instance = new instance(key);
202
212
 
203
213
  let params = [], mainParam = false
204
214
  for (let i = 0; true; i++) {