Skip to content

Commit

Permalink
Merge pull request #18 from ishabo/add-interpreter-options
Browse files Browse the repository at this point in the history
Add interpreter options
  • Loading branch information
carloslfu authored Mar 30, 2020
2 parents a001c78 + ac440d0 commit 7ced29d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xstate-router",
"version": "0.4.2",
"version": "0.4.3",
"description": "XState Router. Add routes to your XState machine.",
"main": "lib/index.js",
"files": [
Expand Down
13 changes: 8 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect } from 'react';
import { pathToRegexp } from 'path-to-regexp'
import { useMachine } from '@xstate/react'
import { Machine, matchesState, StateSchema, EventObject, MachineConfig, MachineOptions, StateMachine, interpret } from 'xstate'
import { Machine, matchesState, StateSchema, EventObject, MachineConfig, MachineOptions, StateMachine, InterpreterOptions, interpret } from 'xstate'
import { getStateNodes } from '@xstate/graph'
import { assign } from 'xstate/lib/actions'
import { createBrowserHistory } from 'history'
Expand Down Expand Up @@ -136,9 +136,11 @@ export function routerMachine<
options = ({} as MachineOptions<TContext, TEvent>),
initialContext = {},
history = createBrowserHistory(),
}: RouterArgs) {
}: RouterArgs,
interpreterOptions?: Partial<InterpreterOptions>
) {
const machine = createRouterMachine({config, options, initialContext, history})
const service = interpret(machine)
const service = interpret(machine, interpreterOptions)
service.start()

handleTransitionEvents(service, history, getRoutes(config))
Expand All @@ -156,9 +158,10 @@ export function useRouterMachine
options = ({} as MachineOptions<TContext, TEvent>),
initialContext = {},
history = createBrowserHistory(),
}: RouterArgs) {
}: RouterArgs,
interpreterOptions?: Partial<InterpreterOptions>) {
const machine = createRouterMachine({config, options, initialContext, history})
const [state, send, service] = useMachine(machine);
const [state, send, service] = useMachine(machine, interpreterOptions);

useEffect(() => {
handleTransitionEvents(service, history, getRoutes(config))
Expand Down

0 comments on commit 7ced29d

Please sign in to comment.