Kelin2025 / effector-factorio

The simplest way to write re-usable features with React + Effector
MIT License
62 stars 6 forks source link

Add support for `@@unitShape` #6

Closed sergeysova closed 1 year ago

sergeysova commented 1 year ago

https://effector.dev/docs/ecosystem-development/unit-shape-protocol

Looks like it would be very useful to use this protocol with useUnit:


const formFactory = modelFactory((options: FactoryOptions) => {
  const loginChanged = createEvent<string>();
  const passwordChanged = createEvent<string>();
  const submitPressed = createEvent();

  const $login = createStore('');
  const $password = createStore('');

  const $form = combine({ login: $login, password: $password });

  const $disabled = options.registerFx.pending;

  $login.on(loginChanged, (prev, next) => next);
  $password.on(passwordChanged, (prev, next) => next);

  sample({
    source: $form,
    clock: submitPressed,
    target: options.registerFx,
  });

  return {
    $login,
    $password,
    $disabled,
    loginChanged,
    passwordChanged,
    submitPressed,
  };
});

const form = formFactory({ registerFx })

function App() {
  const { login, password, disabled, loginChanged, passwordChanged, submitPressed } = useUnit(form)
}

But I think it will be very useful to remove $ from the prefix.