vaderjs 1.1.5 → 1.1.6
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/jsconfig.json +8 -1
- package/package.json +2 -3
- package/tsconfig.json +18 -0
- package/vader.js +2 -0
- package/vaderRouter.js +31 -9
package/jsconfig.json
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vaderjs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "A Reactive Framework for Single-Page Applications (SPA)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "tsc"
|
|
8
|
-
"lint:types": "tsc"
|
|
7
|
+
"test": "tsc --noEmit "
|
|
9
8
|
},
|
|
10
9
|
"repository": {
|
|
11
10
|
"type": "git",
|
package/tsconfig.json
ADDED
package/vader.js
CHANGED
package/vaderRouter.js
CHANGED
|
@@ -195,6 +195,11 @@ class VaderRouter {
|
|
|
195
195
|
) {
|
|
196
196
|
return false;
|
|
197
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* @alias query
|
|
200
|
+
* @type {Object}
|
|
201
|
+
* @property {Object} params - The params object.
|
|
202
|
+
*/
|
|
198
203
|
const query = {};
|
|
199
204
|
|
|
200
205
|
const queryString = window.location.hash.substring(1).split("?")[1];
|
|
@@ -233,9 +238,7 @@ class VaderRouter {
|
|
|
233
238
|
* @description Allows you to perform actions when the currentRoute changes.
|
|
234
239
|
*/
|
|
235
240
|
const res = {
|
|
236
|
-
|
|
237
|
-
this.hooked = false;
|
|
238
|
-
},
|
|
241
|
+
|
|
239
242
|
render: function (selector, data) {
|
|
240
243
|
document.querySelector(selector).innerHTML = data;
|
|
241
244
|
},
|
|
@@ -249,7 +252,12 @@ class VaderRouter {
|
|
|
249
252
|
this.hooked = false;
|
|
250
253
|
return false;
|
|
251
254
|
}
|
|
252
|
-
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @alias kill
|
|
258
|
+
* @description Allows you to kill a route.
|
|
259
|
+
* @param {string} path
|
|
260
|
+
*/
|
|
253
261
|
kill(path) {
|
|
254
262
|
if (this.routes[path]) {
|
|
255
263
|
delete this.routes[path];
|
|
@@ -310,6 +318,10 @@ class VaderRouter {
|
|
|
310
318
|
}
|
|
311
319
|
}
|
|
312
320
|
|
|
321
|
+
/**
|
|
322
|
+
* @alias onload
|
|
323
|
+
* @param {Function} callback
|
|
324
|
+
*/
|
|
313
325
|
onload(callback) {
|
|
314
326
|
// await dom to be done make sure no new elements are added
|
|
315
327
|
if (
|
|
@@ -333,8 +345,16 @@ class VaderRouter {
|
|
|
333
345
|
*/
|
|
334
346
|
on(path, callback) {
|
|
335
347
|
window.addEventListener("hashchange", () => {
|
|
336
|
-
|
|
337
|
-
|
|
348
|
+
/**
|
|
349
|
+
* @alias paramNames
|
|
350
|
+
* @typedef {Array}
|
|
351
|
+
*/
|
|
352
|
+
const paramNames = new Array();
|
|
353
|
+
/**
|
|
354
|
+
* @alias queryNames
|
|
355
|
+
* @typedef {Array}
|
|
356
|
+
*/
|
|
357
|
+
const queryNames = new Array();
|
|
338
358
|
const parsedPath = path
|
|
339
359
|
.split("/")
|
|
340
360
|
.map((part) => {
|
|
@@ -381,6 +401,7 @@ class VaderRouter {
|
|
|
381
401
|
const params = {};
|
|
382
402
|
|
|
383
403
|
for (let i = 0; i < paramNames.length; i++) {
|
|
404
|
+
// @ts-ignore
|
|
384
405
|
params[paramNames[i]] = matches[i + 1];
|
|
385
406
|
}
|
|
386
407
|
if (
|
|
@@ -401,6 +422,7 @@ class VaderRouter {
|
|
|
401
422
|
const queryParts = queryString.split("&");
|
|
402
423
|
for (let i = 0; i < queryParts.length; i++) {
|
|
403
424
|
const queryParam = queryParts[i].split("=");
|
|
425
|
+
// @ts-ignore
|
|
404
426
|
query[queryParam[0]] = queryParam[1];
|
|
405
427
|
}
|
|
406
428
|
}
|
|
@@ -411,9 +433,7 @@ class VaderRouter {
|
|
|
411
433
|
method: "POST",
|
|
412
434
|
};
|
|
413
435
|
const res = {
|
|
414
|
-
|
|
415
|
-
this.hooked = false;
|
|
416
|
-
},
|
|
436
|
+
|
|
417
437
|
/**
|
|
418
438
|
* @alias send
|
|
419
439
|
* @param {String} selector
|
|
@@ -425,6 +445,7 @@ class VaderRouter {
|
|
|
425
445
|
* res.send('#root', '<h1>Hello World</h1>');
|
|
426
446
|
* */
|
|
427
447
|
send: function (selector, data) {
|
|
448
|
+
// @ts-ignore
|
|
428
449
|
document.querySelector(selector).innerHTML = data;
|
|
429
450
|
},
|
|
430
451
|
/**
|
|
@@ -436,6 +457,7 @@ class VaderRouter {
|
|
|
436
457
|
* @description Allows you to perform actions when the currentRoute changes.
|
|
437
458
|
*/
|
|
438
459
|
render: function (selector, data) {
|
|
460
|
+
// @ts-ignore
|
|
439
461
|
document.querySelector(selector).innerHTML = data;
|
|
440
462
|
},
|
|
441
463
|
};
|