Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
9 changes: 4 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"class-methods-use-this": "off",
"consistent-return": "off",
"eqeqeq": "off",
"guard-for-in": "off",
"max-classes-per-file": "off",
"new-cap": "off",
"no-bitwise": "off",
Expand All @@ -35,23 +34,23 @@
"no-underscore-dangle": "off",
"no-unused-expressions": "off",
"no-use-before-define": "off",
"no-void": "off",
"prefer-const": "off",
"prefer-destructuring": ["error", { "object": true, "array": false }],
"prefer-rest-params": "off",
"prefer-promise-reject-errors": "off",
"symbol-description": "off",
"import/extensions": "off",
"import/extensions": ["error", "always"],
"import/no-cycle": "off",
"import/no-extraneous-dependencies": "off",
"import/prefer-default-export": "off"
},
"overrides": [
{
"files": "types/**/*.ts",
"files": "**/*.{ts,tsx}",
"extends": ["airbnb-typescript/base", "prettier"],
"rules": {
"@typescript-eslint/no-shadow": "off",
"@typescript-eslint/no-unused-expressions": "off",
"import/extensions": ["error", "always"],
"import/no-cycle": "off"
}
}
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"ssr": "node ssr/tests/ssr.js",
"test:w": "web-test-runner --watch",
"build:html": "rollup -c",
"prepare": "npm run test:ts && npm run test",
"prepare": "husky install && npm run test:ts && npm run test",
"lint": "eslint .",
"hook:push": "npm run lint && npm run test",
"hook:commit": "npm run lint"
Expand All @@ -104,9 +104,9 @@
"devDependencies": {
"@esm-bundle/chai": "^4.3.4-fix.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@types/chai": "^4.2.18",
"@types/mocha": "^8.0.0",
"@web/test-runner": "^0.13.27",
"@types/chai": "^4.3.9",
"@types/mocha": "^8.2.3",
"@web/test-runner": "^0.13.31",
"eslint": "^8.52.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
Expand All @@ -118,9 +118,6 @@
"typescript": "^5.2.2"
},
"prettier": {
"endOfLine": "lf",
"semi": true,
"singleQuote": false,
"tabWidth": 4
}
}
5 changes: 4 additions & 1 deletion src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ export const createContext = (value) => {
/**
* @type {import("context").ComponentContext<any>}
*/
const context = () => void useProvider(Context, useHost().current);
const context = () => {
useProvider(Context, useHost().current);
return undefined;
};

context.props = {
value: {
Expand Down
24 changes: 15 additions & 9 deletions src/element/custom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export const c = (component, base) => {
super();
this._setup();
this._render = () => component({ ...this._props });
for (const prop in values) this[prop] = values[prop];
for (const prop in values) {
if (Object.prototype.hasOwnProperty.call(values, prop)) {
this[prop] = values[prop];
}
}
}

/**
Expand Down Expand Up @@ -104,7 +108,7 @@ export const c = (component, base) => {
};
});

this.symbolId = this.symbolId || Symbol();
this.symbolId = this.symbolId || Symbol(className);

const hooks = createHooks(
() => this.update(),
Expand Down Expand Up @@ -229,13 +233,15 @@ export const c = (component, base) => {
// @ts-ignore
const superAttrs = super.observedAttributes || [];
for (const prop in props) {
setPrototype(
this.prototype,
prop,
props[prop],
attrs,
values,
);
if (Object.prototype.hasOwnProperty.call(props, prop)) {
setPrototype(
this.prototype,
prop,
props[prop],
attrs,
values,
);
}
}
return Object.keys(attrs).concat(superAttrs);
}
Expand Down
8 changes: 5 additions & 3 deletions src/hooks/create-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ export const createHooks = (update, host, id = 0) => {
*/
const cleanEffectsByType = (tag, unmounted) => {
for (const index in hooks) {
const hook = hooks[index];
if (hook.effect && hook.tag === tag) {
hook.value = hook.effect(hook.value, unmounted);
if (Object.prototype.hasOwnProperty.call(hooks, index)) {
const hook = hooks[index];
if (hook.effect && hook.tag === tag) {
hook.value = hook.effect(hook.value, unmounted);
}
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/tests/use-effect.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "@esm-bundle/chai";
import { createHooks } from "../create-hooks";
import { useEffect } from "../hooks";
import { createHooks } from "../create-hooks.js";
import { useEffect } from "../hooks.js";

describe("src/hooks/use-effect", () => {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/tests/use-event.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "@esm-bundle/chai";
import { createHooks } from "../create-hooks";
import { useEvent } from "../custom-hooks/use-event";
import { createHooks } from "../create-hooks.js";
import { useEvent } from "../custom-hooks/use-event.js";

describe("src/hooks/custom-hooks/use-event", () => {
it("association of useEvent to host", (done) => {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/tests/use-layout-effect.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "@esm-bundle/chai";
import { createHooks } from "../create-hooks";
import { useLayoutEffect } from "../hooks";
import { createHooks } from "../create-hooks.js";
import { useLayoutEffect } from "../hooks.js";

describe("src/hooks/use-effect", () => {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/tests/use-memo.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "@esm-bundle/chai";
import { createHooks } from "../create-hooks";
import { useMemo, useCallback } from "../hooks";
import { createHooks } from "../create-hooks.js";
import { useMemo, useCallback } from "../hooks.js";

describe("src/hooks/use-callback", () => {
it("reflection of useMemo", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/tests/use-prop.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "@esm-bundle/chai";
import { createHooks } from "../create-hooks";
import { useProp } from "../custom-hooks/use-prop";
import { createHooks } from "../create-hooks.js";
import { useProp } from "../custom-hooks/use-prop.js";

describe("src/hooks/custom-hooks/use-prop", () => {
it("manipulation of the DOM object", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/tests/use-reducer.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "@esm-bundle/chai";
import { createHooks } from "../create-hooks";
import { useReducer } from "../hooks";
import { createHooks } from "../create-hooks.js";
import { useReducer } from "../hooks.js";

describe("src/hooks/use-state", () => {
it("initialState", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/tests/use-ref.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "@esm-bundle/chai";
import { createHooks, useRef } from "../create-hooks";
import { createHooks, useRef } from "../create-hooks.js";

describe("src/hooks/use-ref", () => {
it("referencia persistente de creacion", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/tests/use-state.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "@esm-bundle/chai";
import { createHooks } from "../create-hooks";
import { useState } from "../hooks";
import { createHooks } from "../create-hooks.js";
import { useState } from "../hooks.js";

describe("src/hooks/use-state", () => {
it("single execution", () => {
Expand Down
18 changes: 12 additions & 6 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,15 @@ export function renderChildren(children, fragment, parent, id, hydrate, isSvg) {
*/
export function diffProps(node, props, nextProps, handlers, isSvg) {
for (const key in props) {
!(key in nextProps) &&
setProperty(node, key, props[key], null, isSvg, handlers);
if (Object.prototype.hasOwnProperty.call(props, key)) {
!(key in nextProps) &&
setProperty(node, key, props[key], null, isSvg, handlers);
}
}
for (const key in nextProps) {
setProperty(node, key, props[key], nextProps[key], isSvg, handlers);
if (Object.prototype.hasOwnProperty.call(nextProps, key)) {
setProperty(node, key, props[key], nextProps[key], isSvg, handlers);
}
}
}

Expand Down Expand Up @@ -456,9 +460,11 @@ export function setProperty(node, key, prevValue, nextValue, isSvg, handlers) {

if (nextIsObject) {
for (const key in nextValue) {
const value = nextValue[key];
if (prevIsObject && prevValue[key] === value) continue;
setPropertyStyle(style, key, value);
if (Object.prototype.hasOwnProperty.call(nextValue, key)) {
const value = nextValue[key];
if (prevIsObject && prevValue[key] === value) continue;
setPropertyStyle(style, key, value);
}
}
} else {
style.cssText = nextValue;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/element-hooks.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "@esm-bundle/chai";
import { useRef } from "../hooks/create-hooks";
import { useRef } from "../hooks/create-hooks.js";
import { customElementScope } from "./element.test.js";
import { html } from "../../html.js";

Expand Down
2 changes: 1 addition & 1 deletion src/tests/element.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ describe("src/element", () => {

let node = customElementScope(Wc);

let value = Symbol();
let value = Symbol("value");

document.body.appendChild(node);

Expand Down
2 changes: 1 addition & 1 deletion src/tests/internal/set-prototype.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
filterValue,
reflectValue,
getAttr,
} from "../../element/set-prototype";
} from "../../element/set-prototype.js";

describe("internal: getAttr", () => {
it("check getAttr", () => {
Expand Down
10 changes: 5 additions & 5 deletions src/tests/render-children.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ describe("src/render#children", () => {
const root = document.createElement("div");
const ref = {};
const children = [{}, {}, [{}], html`<span ref=${ref} />`];
const id = Symbol();
const id = Symbol("id");
const fragment = renderChildren(children, null, root, id, false);
const childNodes = fragmentToChildNodes(fragment);
expect(childNodes).to.deep.equal([ref.current]);
});
it("Render: Size", () => {
const root = document.createElement("div");
const children = [...Array(10)].map(() => html`<span></span>`);
const id = Symbol();
const id = Symbol("id");
const fragment = renderChildren(children, null, root, id, false);
const childNodes = fragmentToChildNodes(fragment);
expect(childNodes.length).to.equal(children.length);
});
it("nested lists", () => {
const root = document.createElement("div");
const id = Symbol();
const id = Symbol("id");
let count = 0;
const list = [...Array(10)].map((_, index) => {
const list = [...Array(5)].map(
Expand All @@ -76,7 +76,7 @@ describe("src/render#children", () => {
});
it("Render: Simple list rendering", () => {
const root = document.createElement("div");
const id = Symbol();
const id = Symbol("id");
let fragment;
/**
*
Expand Down Expand Up @@ -110,7 +110,7 @@ describe("src/render#children", () => {
});

it("Render: Simple list rendering with keyes", () => {
const id = Symbol();
const id = Symbol("id");
const host = document.createElement("div");
let size = 100;
let fragment;
Expand Down
4 changes: 3 additions & 1 deletion src/tests/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ describe("src/render", () => {
);

for (let key in attrs) {
expect(el.getAttribute(key)).to.equal(attrs[key].expect);
if (Object.prototype.hasOwnProperty.call(attrs, key)) {
expect(el.getAttribute(key)).to.equal(attrs[key].expect);
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/tests/template.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "@esm-bundle/chai";
import { html } from "../../html.js";
import { template } from "../template";
import { template } from "../template.js";

describe("src/template", () => {
it("check", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "@esm-bundle/chai";
import { isEqualArray, isFunction, isObject } from "../utils";
import { isEqualArray, isFunction, isObject } from "../utils.js";

describe("src/utils", () => {
it("isEqualArray", () => {
Expand Down
Loading