Repository: pmndrs/zustand
File: src/middleware.ts (TypeScript)

Code before:
    }
    const namedSet: NamedSet<S> = (state, replace, name) => {
      set(state, replace)
      if (!api.dispatch) {
        api.devtools.send(api.devtools.prefix + (name || 'action'), get())
      }
    }
    const initialState = fn(namedSet, get, api)
    if (!api.devtools) {
      const savedSetState = api.setState
      api.setState = <
        K1 extends keyof S = keyof S,
        K2 extends keyof S = K1,
        K3 extends keyof S = K2,
        K4 extends keyof S = K3
      >(
        state: PartialState<S, K1, K2, K3, K4>,
        replace?: boolean
      ) => {
        savedSetState(state, replace)
        api.devtools.send(api.devtools.prefix + 'setState', api.getState())
      }
      api.devtools = extension.connect({ ...options })
      api.devtools.prefix = options?.name ? `${options.name} > ` : ''
      api.devtools.subscribe((message: any) => {
        if (message.type === 'DISPATCH' && message.state) {
          const ignoreState =
            message.payload.type === 'JUMP_TO_ACTION' ||
            message.payload.type === 'JUMP_TO_STATE'
          if (!api.dispatch && !ignoreState) {
            api.setState(JSON.parse(message.state))
          } else {
            savedSetState(JSON.parse(message.state))
          }
        } else if (
          message.type === 'DISPATCH' &&
          message.payload?.type === 'COMMIT'
        ) {
          api.devtools.init(api.getState())
        } else if (
          message.type === 'DISPATCH' &&
          message.payload?.type === 'IMPORT_STATE'
        ) {
          const actions = message.payload.nextLiftedState?.actionsById
          const computedStates =
            message.payload.nextLiftedState?.computedStates || []

          computedStates.forEach(
            ({ state }: { state: PartialState<S> }, index: number) => {
              const action = actions[index] || api.devtools.prefix + 'setState'


Review comment (suggestion):
```suggestion
      options = typeof options === 'string' ? { name: options } : options
      api.devtools = extension.connect({ ...options })
```

Code after:
      api.devtools = null
      return fn(set, get, api)
    }
    const namedSet: NamedSet<S> = (state, replace, name) => {
      set(state, replace)
      if (!api.dispatch) {
        api.devtools.send(api.devtools.prefix + (name || 'action'), get())
      }
    }
    const initialState = fn(namedSet, get, api)
    if (!api.devtools) {
      const savedSetState = api.setState
      api.setState = <
        K1 extends keyof S = keyof S,
        K2 extends keyof S = K1,
        K3 extends keyof S = K2,
        K4 extends keyof S = K3
      >(
        state: PartialState<S, K1, K2, K3, K4>,
        replace?: boolean
      ) => {
        savedSetState(state, replace)
        api.devtools.send(api.devtools.prefix + 'setState', api.getState())
      }
      options = typeof options === 'string' ? { name: options } : options
      api.devtools = extension.connect({ ...options })
      api.devtools.prefix = options?.name ? `${options.name} > ` : ''
      api.devtools.subscribe((message: any) => {
        if (message.type === 'DISPATCH' && message.state) {
          const ignoreState =
            message.payload.type === 'JUMP_TO_ACTION' ||
            message.payload.type === 'JUMP_TO_STATE'
          if (!api.dispatch && !ignoreState) {
            api.setState(JSON.parse(message.state))
          } else {
            savedSetState(JSON.parse(message.state))
          }
        } else if (
          message.type === 'DISPATCH' &&
          message.payload?.type === 'COMMIT'
        ) {
          api.devtools.init(api.getState())
        } else if (
          message.type === 'DISPATCH' &&
          message.payload?.type === 'IMPORT_STATE'
        ) {
          const actions = message.payload.nextLiftedState?.actionsById
          const computedStates =
            message.payload.nextLiftedState?.computedStates || []

          computedStates.forEach(