<commit_before>import { EventObject, OmniEventObject, ActionObject } from 'xstate';
import { produce, Draft } from 'immer';
import { actionTypes } from 'xstate/lib/actions';

export type ImmerAssigner<TContext, TEvent extends EventObject> = (
  context: Draft<TContext>,
  event: TEvent
) => void;

export interface ImmerAssignAction<TContext, TEvent extends EventObject>
  extends ActionObject<TContext, TEvent> {
  assignment: ImmerAssigner<TContext, TEvent>;
}

export function assign<TContext, TEvent extends EventObject = EventObject>(
  assignment: ImmerAssigner<TContext, TEvent>
): ImmerAssignAction<TContext, TEvent> {
  return {
    type: actionTypes.assign,
    assignment
  };
}

export function updater<TContext, TEvent extends EventObject>(
  context: TContext,
  event: OmniEventObject<TEvent>,
  assignActions: Array<ImmerAssignAction<TContext, TEvent>>
): TContext {
  const updatedContext = context
    ? assignActions.reduce((acc, assignAction) => {
        const { assignment } = assignAction as ImmerAssignAction<
          TContext,
          OmniEventObject<TEvent>
        >;

        const update = produce(acc, interim => void assignment(interim, event));

        return update;
      }, context)
    : context;

  return updatedContext as TContext;
}
<commit_msg>Remove OmniEventObject usage from @xstate/immer<commit_after>import { EventObject, ActionObject } from 'xstate';
import { produce, Draft } from 'immer';
import { actionTypes } from 'xstate/lib/actions';

export type ImmerAssigner<TContext, TEvent extends EventObject> = (
  context: Draft<TContext>,
  event: TEvent
) => void;

export interface ImmerAssignAction<TContext, TEvent extends EventObject>
  extends ActionObject<TContext, TEvent> {
  assignment: ImmerAssigner<TContext, TEvent>;
}

export function assign<TContext, TEvent extends EventObject = EventObject>(
  assignment: ImmerAssigner<TContext, TEvent>
): ImmerAssignAction<TContext, TEvent> {
  return {
    type: actionTypes.assign,
    assignment
  };
}

export function updater<TContext, TEvent extends EventObject>(
  context: TContext,
  event: TEvent,
  assignActions: Array<ImmerAssignAction<TContext, TEvent>>
): TContext {
  const updatedContext = context
    ? assignActions.reduce((acc, assignAction) => {
        const { assignment } = assignAction as ImmerAssignAction<
          TContext,
          TEvent
        >;

        const update = produce(acc, interim => void assignment(interim, event));

        return update;
      }, context)
    : context;

  return updatedContext as TContext;
}

{'fraction_non_alphanumeric': 0.098635477582846, 'fraction_numerical': 0.0, 'mean_word_length': 4.356993736951983, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7371935', 'n_tokens_mistral': 744, 'n_tokens_neox': 737, 'n_words': 193}