Skip to content

Commit

Permalink
Allow stop with unabortables after onDictate (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim authored Jun 1, 2021
1 parent 75400ad commit 0d6fd36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Fixed [#65](https://github.com/compulim/react-dictate-button/issues/65). Setting `started` to `false` after `onDictate` callback should succeed even on an unabortable recognition, by [@compulim](https://github.com/compulim), in PR [#66](https://github.com/compulim/react-dictate-button/pull/66)

## [2.0.0] - 2021-05-16

### Breaking changes
Expand Down
14 changes: 10 additions & 4 deletions packages/component/src/Composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ const Composer = ({
}

recognitionRef.current = undefined;

setReadyState(0);

emitDictateOnEndRef.current && onDictateRef.current && onDictateRef.current({ type: 'dictate' });
if (emitDictateOnEndRef.current) {
onDictateRef.current && onDictateRef.current({ type: 'dictate' });
emitDictateOnEndRef.current = false;
}
},
[emitDictateOnEndRef, onDictateRef, recognitionRef, setReadyState]
);
Expand Down Expand Up @@ -143,15 +145,19 @@ const Composer = ({
const first = rawResults[0];

if (first.isFinal) {
emitDictateOnEndRef.current = false;
// After "onDictate" callback, the caller should be able to set "started" to false on an unabortable recognition.
// TODO: Add test for fortification.
recognitionRef.current = undefined;
setReadyState(0);

onDictateRef.current && onDictateRef.current({ result: results[0], type: 'dictate' });
} else {
onProgressRef.current &&
onProgressRef.current({ abortable: recognitionAbortable(target), results, type: 'progress' });
}
}
},
[emitDictateOnEndRef, onDictateRef, onProgressRef, recognitionRef]
[onDictateRef, onProgressRef, recognitionRef, setReadyState]
);

const handleStart = useCallback(
Expand Down

0 comments on commit 0d6fd36

Please sign in to comment.