Skip to content

Module update - #67

Merged
chermashentsau merged 5 commits into
masterfrom
module-update
Jul 28, 2023
Merged

Module update#67
chermashentsau merged 5 commits into
masterfrom
module-update

Conversation

@chermashentsau

Copy link
Copy Markdown
Collaborator
  1. Добавил модули-фабрики. Смысл в том, чтобы можно было использовать стейт модулей (серверный, клиентский) для создания этих же модулей, как например это происходит в монтируемых модулях, но чего нет в абстрактных.
  2. Добавил в стейт модуля hostAppId по умолчанию, чтобы им так же можно было воспользоваться

@changeset-bot

changeset-bot Bot commented Jul 27, 2023

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5c52412

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@alfalab/scripts-modules Minor
@alfalab/scripts-server Minor
example-modules Patch
example Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

} else if (result.module.factory && typeof result.module.factory === 'function') {

moduleResult = result.module.factory(factoryParams);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше бы тут добавить обработку кейса когда никакое из условий не выполнилось и бросать ошибку. Потому что сейчас если модуль косячный - то потребитель просто получит пустоту как результат хука

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ну и в таком случае unmountFn раньше вытаскивать из лоадера, чтобы при ошибке все равно отмонтирование работало нормально

},
'6': {
title: 'Server state Factory Module',
description: 'Сфабрикованный модуль, фабрика получает состояние с сервера',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Сфабрикованный" как то немного режет ухо, может "модуль-фабрика, который получает состояние с сервера"?




setModule(moduleResult)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так как функция асинхронная, есть вероятность того, что компонент, в котором будет использоваться хук, будет размонтирован до того как функция будет выполнена - произойдет утечка памяти

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и разгруженный модуль никогда не будет unmountFn?.();

@qrik116 qrik116 Jul 28, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Предложение: воспользоваться подходом отмены промиса через сигналы или иную реализацию https://codesandbox.io/s/summer-https-f79wl4?file=/src/App.js

@chermashentsau chermashentsau Jul 28, 2023

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Идея отличная, но думаю, что для следующего ПРа, т.к. затронет как минимум ещё два хука

@chermashentsau
chermashentsau merged commit 7d83c45 into master Jul 28, 2023
@core-ds-bot core-ds-bot mentioned this pull request Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants