-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,507 additions
and
1,143 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class RouterCache { | ||
constructor() { | ||
this.cached = {}; | ||
this.seed = 0; | ||
} | ||
|
||
create(data) { | ||
const key = `[route_cache_id:${++this.seed}]`; | ||
this.cached[key] = data; | ||
return key; | ||
} | ||
|
||
flush(seed) { | ||
if (!seed) return; | ||
let ret = this.cached[seed]; | ||
delete this.cached[seed]; | ||
return ret; | ||
} | ||
} | ||
const routeCache = new RouterCache(); | ||
|
||
|
||
export default routeCache; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
export class RouteLazy { | ||
constructor(importMethod) { | ||
this.importMethod = importMethod; | ||
this.resolved = false; | ||
this.updater = null; | ||
} | ||
|
||
toResolve() { | ||
return new Promise((resolve, reject) => { | ||
let _resolve = v => { | ||
if (this.updater) v = this.updater(v) || v; | ||
this.resolved = true; | ||
resolve(v); | ||
}; | ||
let component = this.importMethod(); | ||
if (component instanceof Promise) { | ||
component.then(c => { | ||
component = c.__esModule ? c.default : c; | ||
return _resolve(component); | ||
}).catch(function () { return reject(arguments); }); | ||
} else _resolve(component); | ||
}); | ||
} | ||
} | ||
|
||
export async function resolveRouteLazyList(matched) { | ||
if (!matched) return; | ||
const toResolve = function (routeLazy) { | ||
if (!routeLazy || !(routeLazy instanceof RouteLazy)) return; | ||
return routeLazy.toResolve(); | ||
}; | ||
for (let r of matched) { | ||
const config = r.config; | ||
await toResolve(config.component, config); | ||
if (config.components) { | ||
for (let key of config.components) await toResolve(config.components[key], config); | ||
} | ||
} | ||
} | ||
|
||
export function lazyImport(importMethod) { | ||
return new RouteLazy(importMethod); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.