Skip to content

Commit

Permalink
Add state.hasTag(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Apr 29, 2021
1 parent 48ab8db commit 8c91497
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions packages/core/src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,12 @@ export class State<
> & { value: TSV } {
return matchesState(parentStateValue as StateValue, this.value);
}

/**
* Whether the current state configuration has a state node with the specified `tag`.
* @param tag
*/
public hasTag(tag: string): boolean {
return this.tags.has(tag);
}
}
12 changes: 6 additions & 6 deletions packages/core/test/tags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('tags', () => {
}
});

expect(machine.initialState.tags.has('go')).toBeTruthy();
expect(machine.transition('yellow', 'TIMER').tags.has('go')).toBeFalsy();
expect(machine.initialState.hasTag('go')).toBeTruthy();
expect(machine.transition('yellow', 'TIMER').hasTag('go')).toBeFalsy();
});

it('supports tags in compound states', () => {
Expand All @@ -47,9 +47,9 @@ describe('tags', () => {
}
});

expect(machine.initialState.tags.has('go')).toBeFalsy();
expect(machine.initialState.tags.has('stop')).toBeTruthy();
expect(machine.initialState.tags.has('crosswalkLight')).toBeTruthy();
expect(machine.initialState.hasTag('go')).toBeFalsy();
expect(machine.initialState.hasTag('stop')).toBeTruthy();
expect(machine.initialState.hasTag('crosswalkLight')).toBeTruthy();
});

it('supports tags in parallel states', () => {
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('tags', () => {
}
});

expect(machine.initialState.tags.has('go')).toBeTruthy();
expect(machine.initialState.hasTag('go')).toBeTruthy();
});

it('stringifies to an array', () => {
Expand Down

0 comments on commit 8c91497

Please sign in to comment.