GeezerVison is showing github.com — :construction: minify improvements · nullstack/nullstack@6e815a1
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: package.json +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 46 | 46 | "webpack-dev-server": "4.11.1", | 47 | 47 | "webpack-hot-middleware": "^2.25.3", | 48 | 48 | "ws": "8.12.0" | | 49 | + }, | | 50 | + "resolutions": { | | 51 | + "terser": "npm:@swc/core" | 49 | 52 | } | 50 | 53 | } |
Collapse file Copy file name to clipboardExpand all lines: scripts/index.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -58,7 +58,7 @@ async function start({ port, env, disk, loader = 'swc' }) { | 58 | 58 |
| 59 | 59 | function build({ output, cache, env, mode = 'ssr' }) { | 60 | 60 | const environment = 'production' | 61 | | - const compiler = getCompiler({ environment, cache }) | | 61 | + const compiler = getCompiler({ environment, cache, loader: 'swc' }) | 62 | 62 | if (env) { | 63 | 63 | process.env.NULLSTACK_ENVIRONMENT_NAME = env | 64 | 64 | } | |
Collapse file Copy file name to clipboard +37Lines changed: 37 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | const registry = {} | 2 | 2 | export default registry | | 3 | +import reqres from "./reqres" | | 4 | +import { generateContext } from "./context" | 3 | 5 |
| 4 | 6 | export function register(klass, functionName) { | 5 | 7 | if (functionName) { | 6 | 8 | registry[`${klass.hash}.${functionName}`] = klass[functionName] | 7 | 9 | } else { | 8 | 10 | registry[klass.hash] = klass | | 11 | + bindStaticProps(klass) | | 12 | + } | | 13 | +} | | 14 | + | | 15 | +function bindStaticProps(klass) { | | 16 | + let parent = klass | | 17 | + while (parent.name !== 'Nullstack') { | | 18 | + const props = Object.getOwnPropertyNames(parent) | | 19 | + for (const prop of props) { | | 20 | + const underscored = prop.startsWith('_') | | 21 | + if (typeof klass[prop] === 'function') { | | 22 | + if (!underscored && !registry[`${parent.hash}.${prop}`]) { | | 23 | + return | | 24 | + } | | 25 | + const propName = `__NULLSTACK_${prop}` | | 26 | + if (!klass[propName]) { | | 27 | + klass[propName] = klass[prop] | | 28 | + } | | 29 | + function _invoke(...args) { | | 30 | + if (underscored) { | | 31 | + return klass[propName].call(klass, ...args) | | 32 | + } | | 33 | + const params = args[0] || {} | | 34 | + const { request, response } = reqres | | 35 | + const subcontext = generateContext({ request, response, ...params }) | | 36 | + return klass[propName].call(klass, subcontext) | | 37 | + } | | 38 | + if (module.hot) { | | 39 | + _invoke.hash = klass[prop].hash | | 40 | + } | | 41 | + klass[prop] = _invoke | | 42 | + klass.prototype[prop] = _invoke | | 43 | + } | | 44 | + } | | 45 | + parent = Object.getPrototypeOf(parent) | 9 | 46 | } | 10 | 47 | } |
Collapse file Copy file name to clipboardExpand all lines: server/runtime.js +2-36Lines changed: 2 additions & 36 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import element from '../shared/element' | 2 | 2 | import fragment from '../shared/fragment' | 3 | | -import registry, { register } from './registry' | 4 | | -import reqres from "./reqres" | 5 | | -import { generateContext } from "./context" | | 3 | +import { register } from './registry' | | 4 | + | 6 | 5 | import Nullstack from './index' | 7 | 6 |
| 8 | 7 | const $runtime = { | @@ -14,39 +13,6 @@ const $runtime = { | 14 | 13 | if (module.hot) { | 15 | 14 | $runtime.accept = function accept(target, ...klasses) { | 16 | 15 | target.hot.accept(); | 17 | | - for (const klass in klasses) { | 18 | | - let parent = klass | 19 | | - while (parent.name !== 'Nullstack') { | 20 | | - const props = Object.getOwnPropertyNames(parent) | 21 | | - for (const prop of props) { | 22 | | - const underscored = prop.startsWith('_') | 23 | | - if (typeof klass[prop] === 'function') { | 24 | | - if (!underscored && !registry[`${parent.hash}.${prop}`]) { | 25 | | - return | 26 | | - } | 27 | | - const propName = `__NULLSTACK_${prop}` | 28 | | - if (!klass[propName]) { | 29 | | - klass[propName] = klass[prop] | 30 | | - } | 31 | | - function _invoke(...args) { | 32 | | - if (underscored) { | 33 | | - return klass[propName].call(klass, ...args) | 34 | | - } | 35 | | - const params = args[0] || {} | 36 | | - const { request, response } = reqres | 37 | | - const subcontext = generateContext({ request, response, ...params }) | 38 | | - return klass[propName].call(klass, subcontext) | 39 | | - } | 40 | | - if (module.hot) { | 41 | | - _invoke.hash = klass[prop].hash | 42 | | - } | 43 | | - klass[prop] = _invoke | 44 | | - klass.prototype[prop] = _invoke | 45 | | - } | 46 | | - } | 47 | | - parent = Object.getPrototypeOf(parent) | 48 | | - } | 49 | | - } | 50 | 16 | } | 51 | 17 |
| 52 | 18 | $runtime.restart = function restart(target, path) { | |
Collapse file Copy file name to clipboardExpand all lines: tests/package.json +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | "author": "", | 6 | 6 | "license": "ISC", | 7 | 7 | "devDependencies": { | | 8 | + "@swc/core": "1.3.35", | 8 | 9 | "cors": "2.8.5", | 9 | 10 | "eslint-plugin-jest": "^27.1.6", | 10 | | - "eslint-plugin-nullstack": "0.0.12", | 11 | 11 | "glob": "^8.0.3", | 12 | 12 | "jest": "29.4.1", | 13 | 13 | "jest-puppeteer": "7.0.0", | | 16 | 16 | }, | 17 | 17 | "types": "../../types/index.d.ts", | 18 | 18 | "overrides": { | 19 | | - "webpack": "5.75.0" | | 19 | + "webpack": "5.75.0", | | 20 | + "terser": "npm:@swc/core" | | 21 | + }, | | 22 | + "resolutions": { | | 23 | + "terser": "npm:@swc/core" | 20 | 24 | }, | 21 | 25 | "scripts": { | 22 | 26 | "start": "node ../scripts/index.js start --port=6969 --env=test --disk", | |
Collapse file Copy file name to clipboardExpand all lines: tests/src/Element.njs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,7 +29,7 @@ class Element extends Nullstack { | 29 | 29 | abbr | 30 | 30 | </element> | 31 | 31 | </element> | 32 | | - <element tag={InnerElement} prop /> | | 32 | + <element tag={this.renderInnerElement} prop /> | 33 | 33 | <element tag={ClassElement} prop /> | 34 | 34 | <element tag={FunctionalElement} prop /> | 35 | 35 | </> | |
Collapse file Copy file name to clipboardExpand all lines: tests/src/Element.test.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,7 +2,7 @@ beforeAll(async () => { | 2 | 2 | await page.goto('http://localhost:6969/element') | 3 | 3 | }) | 4 | 4 |
| 5 | | -describe('FullStackLifecycle', () => { | | 5 | +describe('Element', () => { | 6 | 6 | test('elements can receive any tag b', async () => { | 7 | 7 | const element = await page.$('b[data-tag="b"]') | 8 | 8 | expect(element).toBeTruthy() | |
Collapse file Copy file name to clipboardExpand all lines: tests/src/LazyComponent.njs +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,8 +14,7 @@ class LazyComponent extends Nullstack { | 14 | 14 | render() { | 15 | 15 | return ( | 16 | 16 | <div data-lazy data-safelisted={this.safelisted}> | 17 | | - {' '} | 18 | | - LazyComponent{' '} | | 17 | + LazyComponent | 19 | 18 | </div> | 20 | 19 | ) | 21 | 20 | } | |
Collapse file Copy file name to clipboardExpand all lines: tests/src/LazyComponentLoader.njs +6-3Lines changed: 6 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,12 +11,15 @@ class LazyComponentLoader extends Nullstack { | 11 | 11 | } | 12 | 12 |
| 13 | 13 | async hydrate() { | 14 | | - LazyComponent = (await import('./LazyComponent')).default | | 14 | + this.LazyComponent = (await import('./LazyComponent')).default | | 15 | + console.log(LazyComponent) | | 16 | + this.should = true | 15 | 17 | } | 16 | 18 |
| 17 | 19 | render() { | 18 | | - if (!this.hydrated) return false | 19 | | - return <LazyComponent /> | | 20 | + console.log("RENDER", this.LazyComponent) | | 21 | + if (!this.LazyComponent) return false | | 22 | + return <this.LazyComponent /> | 20 | 23 | } | 21 | 24 |
| 22 | 25 | } | |
Collapse file Copy file name to clipboardExpand all lines: tests/src/RenderableComponent.njs +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,7 +32,7 @@ class RenderableComponent extends Nullstack { | 32 | 32 | <div class="RenderableComponent"> | 33 | 33 | <Falsy /> | 34 | 34 | <div data-object={{ a: 1 }} /> | 35 | | - <div data-function={RenderableComponent} /> | | 35 | + <div data-function={this.renderRenderableComponent} /> | 36 | 36 | <div> this is a normal tag </div> | 37 | 37 | <label for="input"> label </label> | 38 | 38 | <button disabled> disabled button </button> | @@ -42,7 +42,7 @@ class RenderableComponent extends Nullstack { | 42 | 42 | <element class="element" tag={params.condition ? 'div' : 'span'}> | 43 | 43 | element tag | 44 | 44 | </element> | 45 | | - <InnerComponent reference={InnerReference}> | | 45 | + <InnerComponent reference={this.renderInnerReference}> | 46 | 46 | <span class="children"> children </span> | 47 | 47 | </InnerComponent> | 48 | 48 | <ul> | |
|