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 — :sparkles: bind noop and inner references · nullstack/nullstack@edfb535

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • client
    • events.js
  • loaders
    • register-inner-components.js
  • plugins
    • anchorable.js
    • bindable.js
  • shared
    • noop.js
  • tests/src
    • Element.njs
    • Element.test.js
    • RenderableComponent.njs
    • RenderableComponent.test.js
    • TwoWayBindings.test.js
    • TwoWayBindingsExternalComponent.njs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎client/events.js‎

Copy file name to clipboardExpand all lines: client/events.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import router from './router'
22
import { camelize } from '../shared/string';
3+
import noop from '../shared/noop'
34

45
export const eventCallbacks = new WeakMap()
56
export const eventSubjects = new WeakMap()
@@ -58,7 +59,7 @@ export function generateCallback(selector, name) {
5859
object[property] = event.target[valueName];
5960
}
6061
}
61-
if (subject[name] === true) return
62+
if (subject[name] === noop) return
6263
if (Array.isArray(subject[name])) {
6364
for (const subcallback of subject[name]) {
6465
executeEvent(subcallback, subject, event, data)
Collapse file

‎loaders/register-inner-components.js‎

Copy file name to clipboardExpand all lines: loaders/register-inner-components.js
+17-15Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@ module.exports = function (source) {
1111
traverse(ast, {
1212
ClassMethod(path) {
1313
if (path.node.key.name.startsWith('render')) {
14-
traverse(path.node, {
15-
JSXIdentifier(subpath) {
16-
if (/^[A-Z]/.test(subpath.node.name)) {
17-
if (!path.scope.hasBinding(subpath.node.name)) {
18-
const start = path.node.body.body[0].start;
19-
if (!positions.includes(start)) {
20-
positions.push(start);
21-
}
22-
if (!injections[start]) {
23-
injections[start] = [];
24-
}
25-
if (!injections[start].includes(subpath.node.name)) {
26-
injections[start].push(subpath.node.name);
27-
}
14+
function identify(subpath) {
15+
if (/^[A-Z]/.test(subpath.node.name)) {
16+
if (!path.scope.hasBinding(subpath.node.name)) {
17+
const start = path.node.body.body[0].start;
18+
if (!positions.includes(start)) {
19+
positions.push(start);
20+
}
21+
if (!injections[start]) {
22+
injections[start] = [];
23+
}
24+
if (!injections[start].includes(subpath.node.name)) {
25+
injections[start].push(subpath.node.name);
2826
}
2927
}
30-
},
28+
}
29+
}
30+
traverse(path.node, {
31+
JSXIdentifier: identify,
32+
Identifier: identify,
3133
}, path.scope, path);
3234
}
3335
}
Collapse file

‎plugins/anchorable.js‎

Copy file name to clipboardExpand all lines: plugins/anchorable.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import noop from '../shared/noop'
2+
13
function match(node) {
24
return (
35
node &&
@@ -10,7 +12,7 @@ function match(node) {
1012

1113
function transform({ node }) {
1214
if (!match(node)) return
13-
node.attributes.onclick ??= true
15+
node.attributes.onclick ??= noop
1416
}
1517

1618
export default { transform, client: true }
Collapse file

‎plugins/bindable.js‎

Copy file name to clipboardExpand all lines: plugins/bindable.js
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import noop from '../shared/noop'
2+
13
function match(node) {
24
return node?.attributes?.bind !== undefined
35
}
@@ -16,11 +18,11 @@ function transform({ node, environment }) {
1618
node.attributes.name = node.attributes.name || node.attributes.bind;
1719
if (environment.client) {
1820
if (node.attributes.type === 'checkbox' || node.attributes.type === 'radio') {
19-
node.attributes.onclick ??= true;
21+
node.attributes.onclick ??= noop;
2022
} else if (node.type !== 'input' && node.type !== 'textarea') {
21-
node.attributes.onchange ??= true;
23+
node.attributes.onchange ??= noop;
2224
} else {
23-
node.attributes.oninput ??= true;
25+
node.attributes.oninput ??= noop;
2426
}
2527
}
2628
}
Collapse file

‎shared/noop.js‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function noop() { }
Collapse file

‎tests/src/Element.njs‎

Copy file name to clipboardExpand all lines: tests/src/Element.njs
+27-2Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
11
import Nullstack from 'nullstack';
22

3+
class ClassElement extends Nullstack {
4+
5+
render({ prop }) {
6+
return (
7+
<div data-class-component={prop} />
8+
)
9+
}
10+
11+
}
12+
13+
function FunctionalElement({ prop }) {
14+
return (
15+
<div data-functional-component={prop} />
16+
)
17+
}
18+
319
class Element extends Nullstack {
4-
20+
21+
renderInnerElement({ prop }) {
22+
return (
23+
<div data-inner-component={prop} />
24+
)
25+
}
26+
527
render() {
628
return (
7-
<>
29+
<>
830
<element tag="b" data-tag="b">b</element>
931
<element data-tag="fragment">
1032
<element tag="abbr" data-tag="abbr">abbr</element>
1133
</element>
34+
<element tag={InnerElement} prop />
35+
<element tag={ClassElement} prop />
36+
<element tag={FunctionalElement} prop />
1237
</>
1338
)
1439
}
Collapse file

‎tests/src/Element.test.js‎

Copy file name to clipboardExpand all lines: tests/src/Element.test.js
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,20 @@ describe('FullStackLifecycle', () => {
1919
expect(element).toBeFalsy();
2020
});
2121

22+
test('elements can be inner components and receive props', async () => {
23+
const element = await page.$('[data-inner-component]');
24+
expect(element).toBeTruthy();
25+
});
26+
27+
test('elements can be class components and receive props', async () => {
28+
const element = await page.$('[data-class-component]');
29+
expect(element).toBeTruthy();
30+
});
31+
32+
test('elements can be functional components and receive props', async () => {
33+
const element = await page.$('[data-functional-component]');
34+
expect(element).toBeTruthy();
35+
});
36+
37+
2238
});
Collapse file

‎tests/src/RenderableComponent.njs‎

Copy file name to clipboardExpand all lines: tests/src/RenderableComponent.njs
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ class RenderableComponent extends Nullstack {
66
return <div data-nested />
77
}
88

9-
renderInnerComponent({ children }) {
9+
renderInnerComponent({ children, reference: Reference }) {
1010
return (
1111
<div class="InnerComponent">
1212
<p> Inner Component </p>
1313
<NestedInnerComponent />
14+
<Reference prop />
1415
{children}
1516
</div>
1617
)
1718
}
1819

20+
renderInnerReference({ prop }) {
21+
return (
22+
<div data-reference={prop} />
23+
)
24+
}
25+
1926
renderFalsy() {
2027
return false;
2128
}
@@ -37,7 +44,7 @@ class RenderableComponent extends Nullstack {
3744
<element class="element" tag={params.condition ? 'div' : 'span'}>
3845
element tag
3946
</element>
40-
<InnerComponent>
47+
<InnerComponent reference={InnerReference}>
4148
<span class="children"> children </span>
4249
</InnerComponent>
4350
<ul>
Collapse file

‎tests/src/RenderableComponent.test.js‎

Copy file name to clipboardExpand all lines: tests/src/RenderableComponent.test.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ describe('RenderableComponent', () => {
8484
expect(element).toBeFalsy();
8585
});
8686

87+
test('inner components can be referenced and receive props', async () => {
88+
const element = await page.$('[data-reference]');
89+
expect(element).toBeTruthy();
90+
});
91+
8792
});
8893

8994
describe('RenderableComponent ?condition=true', () => {
Collapse file

‎tests/src/TwoWayBindings.test.js‎

Copy file name to clipboardExpand all lines: tests/src/TwoWayBindings.test.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,10 @@ describe('TwoWayBindings', () => {
205205
expect(element).toBeTruthy();
206206
});
207207

208+
test('custom bindable components receive a no op function if no onchange is passed to them', async () => {
209+
await page.waitForSelector('[data-onchange="noop"]')
210+
const element = await page.$('[data-onchange="noop"]');
211+
expect(element).toBeTruthy();
212+
});
213+
208214
});

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.