Skip to content
Merged

Next #114

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/instanceProxyHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { generateContext } from './context';
const instanceProxyHandler = {
get(target, name) {
if (name === '_isProxy') return true;
if (!name.startsWith('_') && typeof (target[name]) == 'function' && name !== 'constructor') {
if (!target[name]?.name?.startsWith('_') && !name.startsWith('_') && typeof (target[name]) == 'function' && name !== 'constructor') {
const { [name]: named } = {
[name]: (args) => {
const context = generateContext({ ...target._attributes, ...args, self: target._self });
Expand All @@ -17,7 +17,7 @@ const instanceProxyHandler = {
return Reflect.get(...arguments);
},
set(target, name, value) {
if (!name.startsWith('_')) {
if (!value?.name?.startsWith('_') && !name.startsWith('_')) {
target[name] = generateObjectProxy(name, value);
client.update();
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nullstack",
"version": "0.11.8",
"version": "0.11.9",
"description": "Full-stack Javascript Components for one-dev armies",
"main": "nullstack.js",
"author": "Mortaro",
Expand Down
2 changes: 1 addition & 1 deletion server/instanceProxyHandler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const instanceProxyHandler = {
get(target, name) {
if (!name.startsWith('_') && typeof (target[name]) == 'function' && name !== 'constructor') {
if (!target[name]?.name?.startsWith('_') && !name.startsWith('_') && typeof (target[name]) == 'function' && name !== 'constructor') {
return (args) => {
const context = target._scope.generateContext({ ...target._attributes, ...args, self: target._self });
return target[name](context);
Expand Down
10 changes: 9 additions & 1 deletion tests/src/UnderscoredAttributes.njs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ const underscoredObject = {
}
}

function _underscored(value) {
this.e = value
}

class UnderscoredAttributes extends Nullstack {

a = 0
b = 0
c = 0
d = 0
e = 0

_underscoredMethod(value) {
this.a = value
Expand All @@ -25,18 +30,21 @@ class UnderscoredAttributes extends Nullstack {
this.b = value
}

notUnderscored = _underscored

hydrate() {
this._underscoredMethod(1)
this._underscoredAttributeFunction(1)
this._underscoredAfterConstructor = underscoredAfterConstructor
this._underscoredAfterConstructor(1)
this._underscoredObject = underscoredObject
this._underscoredObject.withoutUnderscore(1)
this.notUnderscored(1)
}

render() {
return (
<div data-a={this.a} data-b={this.b} data-c={this.c} data-d={this.d}>
<div data-a={this.a} data-b={this.b} data-c={this.c} data-d={this.d} data-e={this.e}>
<span>UnderscoredAttributes</span>
</div>
)
Expand Down
5 changes: 5 additions & 0 deletions tests/src/UnderscoredAttributes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ describe('UnderscoredAttributes', () => {
expect(element).toBeTruthy();
});

test('keys assigned with a function that name is underscored do not receive the context as argument', async () => {
const element = await page.$('[data-e="1"]');
expect(element).toBeTruthy();
});

});

afterAll(async () => {
Expand Down