Skip to content

Commit

Permalink
[fix] Property Descriptor bug of watch decorator at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery committed Feb 1, 2022
1 parent c7f06b0 commit 2118260
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
tags:
- v*
jobs:
Build-and-Deploy:
Build-and-Publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions MobX/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-web-cell",
"version": "0.4.0-rc.3",
"version": "0.4.0-rc.4",
"license": "LGPL-3.0",
"author": "shiy2008@gmail.com",
"description": "MobX adaptor for WebCell v2",
Expand All @@ -24,7 +24,7 @@
},
"dependencies": {
"mobx": ">4.0.0 <6.0.0",
"web-cell": "^2.4.0-rc.4"
"web-cell": "^2.4.0-rc.5"
},
"devDependencies": {
"@parcel/packager-ts": "^2.2.1",
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": "web-cell",
"version": "2.4.0-rc.4",
"version": "2.4.0-rc.5",
"description": "Web Components engine based on JSX & TypeScript",
"keywords": [
"web",
Expand Down
19 changes: 8 additions & 11 deletions source/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@ export function watch(
meta?: PropertyDescriptor
) {
const accessor = !!(meta?.get || meta?.set);
meta = meta || Object.getOwnPropertyDescriptor(prototype, key) || {};

meta.set =
meta.set ||
function (this: WebCellComponent, value) {
this.setProps({ [key]: value });
};
meta.get =
meta.get ||
function () {
return this.props[key];
};
if (!accessor) meta = {};

meta.set ||= function (this: WebCellComponent, value) {
this.setProps({ [key]: value });
};
meta.get ||= function () {
return this.props[key];
};
(meta.configurable = true), (meta.enumerable = true);

if (!accessor) Object.defineProperty(prototype, key, meta);
Expand Down

0 comments on commit 2118260

Please sign in to comment.