Skip to content

Commit

Permalink
🐛 Fixes nested setter regression (#55)
Browse files Browse the repository at this point in the history
* 🐛 Fixes handling of nested setter data accessing

* ⬆️ Upgrades Deps

* 🚨 Resolves Linting Issues
  • Loading branch information
ekwoka authored Jun 25, 2024
1 parent a2c8d24 commit 093eeed
Show file tree
Hide file tree
Showing 9 changed files with 3,005 additions and 2,514 deletions.
86 changes: 43 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"lint:prettier": "prettier --write ./**/src/*",
"lint:staged": "lint-staged",
"precommit": "run-s lint:staged build size",
"prepare": "husky install",
"prepare": "husky",
"size": "node scripts/getSize.js",
"size:test": "NODE_ENV=test node scripts/getSize.js",
"test": "vitest",
Expand All @@ -35,27 +35,27 @@
},
"devDependencies": {
"@milahu/patch-package": "6.4.14",
"@trivago/prettier-plugin-sort-imports": "4.2.1",
"@types/node": "20.8.8",
"@typescript-eslint/eslint-plugin": "6.9.0",
"@typescript-eslint/parser": "6.9.0",
"@vitest/coverage-c8": "0.32.2",
"@trivago/prettier-plugin-sort-imports": "4.3.0",
"@types/node": "20.14.8",
"@typescript-eslint/eslint-plugin": "7.14.1",
"@typescript-eslint/parser": "7.14.1",
"@vitest/coverage-v8": "1.6.0",
"alpinets": "workspace:*",
"esbuild": "0.19.5",
"esbuild": "0.21.5",
"eslint": "8.52.0",
"happy-dom": "9.1.9",
"husky": "8.0.3",
"lint-staged": "15.0.2",
"husky": "9.0.11",
"lint-staged": "15.2.7",
"npm-run-all": "4.1.5",
"prettier": "3.0.3",
"prettier": "3.3.2",
"pretty-bytes": "6.1.1",
"typescript": "5.2.2",
"vite": "4.5.0",
"vite-plugin-dts": "3.6.1",
"vite-plugin-external-deps": "0.0.2",
"vite-plugin-workspace-source": "0.0.1",
"vite-tsconfig-paths": "4.2.1",
"vitest": "0.34.6",
"typescript": "5.5.2",
"vite": "5.3.1",
"vite-plugin-dts": "3.9.1",
"vite-plugin-external-deps": "0.0.3",
"vite-plugin-workspace-source": "0.0.3",
"vite-tsconfig-paths": "4.3.2",
"vitest": "1.6.0",
"vitest-dom": "0.1.1"
},
"lint-staged": {
Expand All @@ -79,35 +79,35 @@
},
"pnpm": {
"overrides": {
"typescript@<5.2.2": "5.2.2",
"typescript": "$typescript",
"semver@<7.5.4": ">=7.5.4",
"happy-dom@>9.1.9": "9.1.9",
"@babel/traverse@<7.23.2": ">=7.23.2",
"esbuild@<0.19.5": "0.19.5",
"@esbuild/android-arm@<0.19.5": "0.19.5",
"@esbuild/android-arm64@<0.19.5": "0.19.5",
"@esbuild/android-x64@<0.19.5": "0.19.5",
"@esbuild/darwin-arm64@<0.19.5": "0.19.5",
"@esbuild/darwin-x64@<0.19.5": "0.19.5",
"@esbuild/freebsd-arm64@<0.19.5": "0.19.5",
"@esbuild/freebsd-x64@<0.19.5": "0.19.5",
"@esbuild/linux-arm@<0.19.5": "0.19.5",
"@esbuild/linux-arm64@<0.19.5": "0.19.5",
"@esbuild/linux-ia32@<0.19.5": "0.19.5",
"@esbuild/linux-loong64@<0.19.5": "0.19.5",
"@esbuild/linux-mips64el@<0.19.5": "0.19.5",
"@esbuild/linux-ppc64@<0.19.5": "0.19.5",
"@esbuild/linux-riscv64@<0.19.5": "0.19.5",
"@esbuild/linux-s390x@<0.19.5": "0.19.5",
"@esbuild/linux-x64@<0.19.5": "0.19.5",
"@esbuild/netbsd-x64@<0.19.5": "0.19.5",
"@esbuild/openbsd-x64@<0.19.5": "0.19.5",
"@esbuild/sunos-x64@<0.19.5": "0.19.5",
"@esbuild/win32-arm64@<0.19.5": "0.19.5",
"@esbuild/win32-ia32@<0.19.5": "0.19.5",
"@esbuild/win32-x64@<0.19.5": "0.19.5",
"vite@=4.5.0": ">=4.5.1",
"vite@>=4.0.0 <=4.5.1": ">=4.5.2"
"esbuild": "$esbuild",
"@esbuild/android-arm": "$esbuild",
"@esbuild/android-arm64": "$esbuild",
"@esbuild/android-x64": "$esbuild",
"@esbuild/darwin-arm64": "$esbuild",
"@esbuild/darwin-x64": "$esbuild",
"@esbuild/freebsd-arm64": "$esbuild",
"@esbuild/freebsd-x64": "$esbuild",
"@esbuild/linux-arm": "$esbuild",
"@esbuild/linux-arm64": "$esbuild",
"@esbuild/linux-ia32": "$esbuild",
"@esbuild/linux-loong64": "$esbuild",
"@esbuild/linux-mips64el": "$esbuild",
"@esbuild/linux-ppc64": "$esbuild",
"@esbuild/linux-riscv64": "$esbuild",
"@esbuild/linux-s390x": "$esbuild",
"@esbuild/linux-x64": "$esbuild",
"@esbuild/netbsd-x64": "$esbuild",
"@esbuild/openbsd-x64": "$esbuild",
"@esbuild/sunos-x64": "$esbuild",
"@esbuild/win32-arm64": "$esbuild",
"@esbuild/win32-ia32": "$esbuild",
"@esbuild/win32-x64": "$esbuild",
"vite": "$vite",
"braces@<3.0.3": ">=3.0.3"
}
}
}
4 changes: 2 additions & 2 deletions packages/alpinets/src/directives/x-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ const getInputValue = (
return modifiers.includes('number')
? safeParseNumber(rawValue)
: modifiers.includes('trim')
? rawValue.trim()
: rawValue;
? rawValue.trim()
: rawValue;
}
});
};
Expand Down
1 change: 0 additions & 1 deletion packages/alpinets/src/directives/x-show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ directive(
const evaluate = evaluateLater<boolean>(el, expression);

// store old value when the element is hidden so we can restore it later
// TODO: implement onto element attributes to work with other directives
let oldDisplay = el.style.display !== 'none' ? el.style.display : null;

// We're going to set this function on the element directly so that
Expand Down
15 changes: 8 additions & 7 deletions packages/alpinets/src/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ export type InterceptorObject<T = unknown> = {
initialize: (data: Record<string, unknown>, path: string, key: string) => T;
};

type InferInterceptor<T> = T extends InterceptorObject<infer U>
? U
: T extends Record<string | number | symbol, unknown>
? {
[K in keyof T]: InferInterceptor<T[K]>;
}
: T;
type InferInterceptor<T> =
T extends InterceptorObject<infer U>
? U
: T extends Record<string | number | symbol, unknown>
? {
[K in keyof T]: InferInterceptor<T[K]>;
}
: T;

export type InferInterceptors<T> = {
[K in keyof T]: InferInterceptor<T[K]>;
Expand Down
22 changes: 13 additions & 9 deletions packages/alpinets/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,27 @@ const proxyMerger: ProxyHandler<wrappedProxy> = {
has(proxies, name) {
if (name == Symbol.unscopables) return false;

return proxies.objects.some((obj) => Reflect.has(obj, name));
return proxies.objects.some(
(obj) =>
Object.prototype.hasOwnProperty.call(obj, name) ||
Reflect.has(obj, name),
);
},
get(proxies, name, thisProxy) {
if (name == 'toJSON') return collapseProxies;
return Reflect.get(
proxies.objects.find((obj) => Reflect.has(obj, name)) ?? {},
name as string,
thisProxy,
);
const target = proxies.objects.find((obj) => Reflect.has(obj, name)) || {};
return Reflect.get(target, name as string, thisProxy);
},
set(proxies, name, value, thisProxy) {
const target =
proxies.objects.find((obj) => Reflect.has(obj, name)) ||
proxies.objects.at(-1);
proxies.objects.find((obj) =>
Object.prototype.hasOwnProperty.call(obj, name),
) || proxies.objects.at(-1);
const descriptor = Object.getOwnPropertyDescriptor(target, name);
if (descriptor?.set && descriptor?.get)
return Reflect.set(target, name, value, thisProxy);
// Can't use Reflect.set here due to [upstream bug](https://github.com/vuejs/core/blob/31abdc8adad569d83b476c340e678c4daa901545/packages/reactivity/src/baseHandlers.ts#L148) in @vue/reactivity
return descriptor.set.call(thisProxy, value) || true;
// return Reflect.set(target, name, value, thisProxy);
return Reflect.set(target, name, value);
},
};
26 changes: 22 additions & 4 deletions packages/alpinets/tests/scope.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mergeProxies } from '../src/scope';
import { reactive } from '@vue/reactivity';

describe('mergeProxies', () => {
it('allows getting keys from object list', () => {
Expand All @@ -22,7 +23,20 @@ describe('mergeProxies', () => {
});
it('allows getters and setters to access the merged proxy', () => {
const objects = [
{ foo: 'bar' },
{
get bar() {
return this.qux.quux;
},
set bar(value) {
this.qux.quux = value;
},
},
{
foo: 'bar',
qux: {
quux: 'quuz',
},
},
{
foo: 'buzz',
get fizz() {
Expand All @@ -32,15 +46,19 @@ describe('mergeProxies', () => {
this.foo = value;
},
},
];
].map(reactive);
const proxy = mergeProxies(objects);
expect(proxy.bar).toBe('quuz');
expect(proxy.foo).toBe('bar');
expect(proxy.fizz).toBe('bar');
proxy.fizz = 'baz';
expect(proxy.foo).toBe('baz');
expect(proxy.fizz).toBe('baz');
expect(objects[0].foo).toBe('baz');
expect(objects[1].foo).toBe('buzz');
expect(objects[1].foo).toBe('baz');
expect(objects[2].foo).toBe('buzz');
Reflect.set(proxy, 'bar', 'quuy');
expect(proxy.bar).toBe('quuy');
expect(objects[1].qux.quux).toBe('quuy');
});
it('properly works with classes', () => {
class Count {
Expand Down
Loading

0 comments on commit 093eeed

Please sign in to comment.