summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2025-04-21 12:03:36 +0300
committerAsko Nõmm <asko@nmm.ee>2025-04-21 12:03:36 +0300
commit1a9481066ad2fc02ebe1fb6a2e37ab30918bc065 (patch)
tree55022d76d0b75921c9b89969d11abe08a3dc0b53
parentb60e4887618f2b07c638a7fc0d0cff274e99e8ab (diff)
Refactor dispatch parameter naming from 'withData' to 'with' for consistency
-rw-r--r--README.md8
-rw-r--r--deno.json2
-rw-r--r--src/shapex.test.ts2
-rw-r--r--src/shapex.ts10
4 files changed, 11 insertions, 11 deletions
diff --git a/README.md b/README.md
index e92898b..5117fd5 100644
--- a/README.md
+++ b/README.md
@@ -87,7 +87,7 @@ Subscriptions listen to events or changes to state. Each subscription must retur
state: T, // optional
dispatch: {
to: "event-to-dispatch",
- withData: {} // optional
+ with: {} // optional
} // optional
}
```
@@ -99,10 +99,10 @@ You can also dispatch multiple events by passing an array of objects, like so:
state: T,
dispatch: [{
to: "event-to-dispatch",
- withData: {}
+ with: {}
},{
to: "another-event-to-dispatch",
- withData: {}
+ with: {}
}]
}
```
@@ -212,7 +212,7 @@ app.subscribe("some-event-name", (state) => {
state,
dispatch: {
to: "counter-increase",
- withData: 5,
+ with: 5,
},
};
});
diff --git a/deno.json b/deno.json
index 7eac7d1..e46d899 100644
--- a/deno.json
+++ b/deno.json
@@ -1,6 +1,6 @@
{
"name": "@shapex/shapex",
- "version": "2.0.0",
+ "version": "2.1.0",
"license": "MIT",
"exports": "./src/shapex.ts",
"imports": {
diff --git a/src/shapex.test.ts b/src/shapex.test.ts
index 5c555b0..55e38ae 100644
--- a/src/shapex.test.ts
+++ b/src/shapex.test.ts
@@ -161,7 +161,7 @@ describe("dispatch", () => {
$.subscribe("parent-event", (state) => ({
state,
- dispatch: { to: "nested-event", withData: "arg-value" },
+ dispatch: { to: "nested-event", with: "arg-value" },
}));
$.dispatch("parent-event");
diff --git a/src/shapex.ts b/src/shapex.ts
index d36e5e4..0366934 100644
--- a/src/shapex.ts
+++ b/src/shapex.ts
@@ -4,7 +4,7 @@
*/
export type SubscriptionResponseDispatch<W extends unknown = undefined> = {
to: string;
- withData?: W;
+ with?: W;
};
/**
@@ -258,15 +258,15 @@ export default function ShapeX<T extends object>(
if (response.dispatch) {
if (isSubscriptionResponseList(response.dispatch)) {
for (const dispatchee of response.dispatch) {
- if (dispatchee.withData) {
- dispatch(dispatchee.to, dispatchee.withData);
+ if (dispatchee.with) {
+ dispatch(dispatchee.to, dispatchee.with);
} else {
dispatch(dispatchee.to);
}
}
} else {
- if (response.dispatch.withData) {
- dispatch(response.dispatch.to, response.dispatch.withData);
+ if (response.dispatch.with) {
+ dispatch(response.dispatch.to, response.dispatch.with);
} else {
dispatch(response.dispatch.to);
}