GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — :construction: lazy files · nullstack/nullstack@8c15083

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • client
    • lazy.js
  • loaders
    • debug.js
  • server
    • lazy.js
  • shared
    • lazyComponent.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎client/lazy.js‎

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import LazyComponent from "../shared/lazyComponent"
2+
3+
export default function lazy(_hash, importer) {
4+
return class extends LazyComponent {
5+
importer = importer
6+
}
7+
}
Collapse file

‎loaders/debug.js‎

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function (source, map) {
2+
if (this.resourcePath.includes('Application.njs')) {
3+
console.log("DEBUG")
4+
require('fs').writeFileSync('debug.njs', source)
5+
}
6+
this.callback(null, source, map)
7+
}
Collapse file

‎server/lazy.js‎

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import LazyComponent from "../shared/lazyComponent"
2+
3+
const queue = {}
4+
5+
export default function lazy(hash, importer) {
6+
queue[hash] = importer
7+
return class extends LazyComponent {
8+
importer = importer
9+
}
10+
}
11+
12+
export async function load(hash) {
13+
const fileHash = module.hot ? hash.split('___')[0] : hash.slice(0, 8)
14+
if (!queue[fileHash]) return
15+
const importer = queue[fileHash]
16+
delete queue[fileHash]
17+
return importer()
18+
}
Collapse file

‎shared/lazyComponent.js‎

Copy file name to clipboard
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import element from './element'
2+
3+
class LazyComponent {
4+
5+
constructor(scope) {
6+
this.server = scope.context.server
7+
}
8+
9+
async initiate() {
10+
this.component = (await this.importer()).default
11+
}
12+
13+
render() {
14+
if (!this.component) return false
15+
const { key, ...attributes } = this._attributes
16+
return element(this.component, attributes)
17+
}
18+
19+
toJSON() {
20+
return null
21+
}
22+
23+
}
24+
25+
export default LazyComponent

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.