Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed @xstate/react UMD build by redeclaring toObserver #1950

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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