Skip to content

Commit aef18ec

Browse files
committed
use user provided name in action or generate a hash
1 parent c2968fb commit aef18ec

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/data/action.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("action", () => {
4444
expect(testAction.url).toBe("https://action/test-action");
4545
});
4646

47-
test.skip("should create action with auto-generated hash when no `name` provided", () => {
47+
test("should create action with auto-generated hash when no `name` provided", () => {
4848
const testFn = async (data: string) => `result: ${data}`;
4949
const testAction = action(testFn);
5050

src/data/action.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,13 @@ export function action<T extends Array<any>, U = void>(
135135
return p.then(handler(), handler(true));
136136
}
137137
const o = typeof options === "string" ? { name: options } : options;
138+
const name = o.name || (!isServer ? String(hashString(fn.toString())) : undefined);
138139
const url: string =
139140
(fn as any).url ||
140-
(o.name && `https://action/${o.name}`) ||
141-
(!isServer ? `https://action/${hashString(fn.toString())}` : "");
141+
(name && `https://action/${name}`) ||
142+
"";
142143
mutate.base = url;
143-
if (o.name) Object.defineProperty(mutate, 'name', { value: o.name, writable: false, configurable: true });
144+
if (name) Object.defineProperty(mutate, 'name', { value: name, writable: false, configurable: true });
144145
return toAction(mutate, url);
145146
}
146147

0 commit comments

Comments
 (0)