Skip to content

Commit

Permalink
Update API
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-go committed Jan 2, 2024
1 parent 6c9f4d0 commit a861e2d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Hat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ namespace Hat

/**
* Enables a hat to have the ability to respond to signaling functions.
* Marks the hat argument as a hat, if it has not been done so already.
*/
export function watch<H extends F, F extends (...args: any[]) => void>(hat: IHat, signal: F, handler: H)
{
if ((hats.get(hat.head) || []).length === 0)
Hat.wear(hat);

const name = getSignalClassName(signal);
const signalsArray = signals.get(hat.head) || [];
signalsArray.push([signal, handler.bind(hat)]);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@squaresapp/hatjs",
"author": "Paul Gordon",
"description": "Utility Functions For Anonymous Controller Classes",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ The HatJS library is a stateless library of utility functions that allow you to
`Hat.over()` - Scans upward through the DOM, starting at the specified Node, looking for the first element wearing a Hat of the specified type. (Throws an exception)
`Hat.under()` - Finds all descendent elements that have an attached Hat of the specified type, that exist underneath the specified Node or Hat.
`Hat.watch(object, signal, handler)` - Enables a hat to have the ability to respond to signaling functions.
`Hat.signal(SignalingFunction, ...signalingFunctionArguments)` - Invokes the watch handlers on all other hats in the DOM that have subscribed to the specified signaling function, and passes the specified arguments to each call.

0 comments on commit a861e2d

Please sign in to comment.