Skip to content

Commit

Permalink
Fixed @xstate/react UMD build by redeclaring toObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Feb 18, 2021
1 parent cf3cefa commit 2326196
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/unlucky-schools-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xstate/react': patch
---

Fixed an issue with `toObserver` being internally imported from `xstate/lib/utils` which has broken UMD build and the declared peer dep contract.
21 changes: 20 additions & 1 deletion packages/xstate-react/src/useInterpret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,31 @@ import {
Typestate,
Observer
} from 'xstate';
import { toObserver } from 'xstate/lib/utils';
import { MaybeLazy } from './types';
import useConstant from './useConstant';
import { UseMachineOptions } from './useMachine';
import { useReactEffectActions } from './useReactEffectActions';

// copied from core/src/utils.ts
// it avoids a breaking change between this package and XState which is its peer dep
function toObserver<T>(
nextHandler: Observer<T> | ((value: T) => void),
errorHandler?: (error: any) => void,
completionHandler?: () => void
): Observer<T> {
if (typeof nextHandler === 'object') {
return nextHandler;
}

const noop = () => void 0;

return {
next: nextHandler,
error: errorHandler || noop,
complete: completionHandler || noop
};
}

export function useInterpret<
TContext,
TEvent extends EventObject,
Expand Down

0 comments on commit 2326196

Please sign in to comment.