Skip to content

Commit bbf2bf2

Browse files
os-billclaude
andauthored
refactor(examples): wrap the two in-repo hook examples in defineHook() (#17532)
`examples/app-crm/src/hooks/opportunity.hook.ts` and `examples/app-todo/src/objects/task.hook.ts` were the only two real lifecycle hooks in the repository and both used the bare `: Hook` literal form, which the published data skill teaches against. Every field inside each object is byte-identical; only the import, the opening line and the closing brace move. Claude-Session: https://claude.ai/code/session_01MkQhmuuJAVDjmeWNixwDDH Co-authored-by: Claude <noreply@anthropic.com>
1 parent edaf3b2 commit bbf2bf2

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

3-
import type { Hook, HookContext } from '@objectstack/spec/data';
3+
import { defineHook, type HookContext } from '@objectstack/spec/data';
44

55
/**
66
* Pin the probability to 100% when an opportunity is marked Closed Won,
77
* and 0% when Closed Lost. Demonstrates a basic before-update hook.
88
*/
9-
export const OpportunityStageHook: Hook = {
9+
export const OpportunityStageHook = defineHook({
1010
name: 'opportunity_stage_probability',
1111
object: 'crm_opportunity',
1212
events: ['beforeInsert', 'beforeUpdate'],
@@ -16,4 +16,4 @@ export const OpportunityStageHook: Hook = {
1616
if (input.stage === 'closed_won') input.probability = 100;
1717
if (input.stage === 'closed_lost') input.probability = 0;
1818
},
19-
};
19+
});

examples/app-todo/src/objects/task.hook.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

3-
import { HookContext, Hook } from '@objectstack/spec/data';
3+
import { defineHook, type HookContext } from '@objectstack/spec/data';
44

55
/**
66
* Lifecycle logic for `todo_task` — insert defaults and the completion stamp.
@@ -47,7 +47,7 @@ import { HookContext, Hook } from '@objectstack/spec/data';
4747
* timestamp that every report and list view reads as fact. The same
4848
* `readonly`/strip reasoning applies — only a hook can write the clear.
4949
*/
50-
const taskHook: Hook = {
50+
const taskHook = defineHook({
5151
name: 'task_logic',
5252
object: 'todo_task',
5353
events: ['beforeInsert', 'beforeUpdate', 'afterUpdate'],
@@ -120,6 +120,6 @@ const taskHook: Hook = {
120120
// runs daily and selects on `due_date` directly.
121121
}
122122
}
123-
};
123+
});
124124

125125
export default taskHook;

0 commit comments

Comments
 (0)