Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fresh() doesn't call any lifecycle Hook #1722

Open
abd777 opened this issue Nov 1, 2023 · 4 comments
Open

fresh() doesn't call any lifecycle Hook #1722

abd777 opened this issue Nov 1, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@abd777
Copy link

abd777 commented Nov 1, 2023

Environment

No response

Reproduction

Playground

Describe the bug

I need to listen for the lifecycle hook inside the Model when the fresh() is called , but no any lifecycle hook is listening to fresh() while if i use save() it works

For now i'm using this as a workaround

const repo = useRepo(REPO_NAME)
// clear everything
repo.flush()
// then save , i.e to trigger the lifecycle
repo.save(NEW_DATA)

ideally fresh() should also be a lifecycle hook trigger

Additional context

No response

Logs

No response

@harmyderoman
Copy link

Actually, it can be useful, if you have one mutator that doesn't trigger the hooks. For example, if you need to save raw data from a backend.

@abd777
Copy link
Author

abd777 commented Nov 25, 2023

@harmyderoman I agree with you , But the issue is that in most cases we need to check the hooks ( as we're using saving
and other hooks for other functions )

May be we can add an optional raw parameter like {raw:true} as the last config object and if raw is true we can keep it as it is , otherwise we can listen for the hooks

@CodeDredd
Copy link
Owner

Hmmm interesting. I try to get my thoughts around that. You both have valid points.
I think flush is getting hooks and i also add the option to avoid hooks.

@CodeDredd CodeDredd added enhancement New feature or request and removed pending triage labels Jan 16, 2024
@groenroos
Copy link

Ran into this today - I wanted to use lifecycle hooks to normalise & process raw data from the backend into a predictable and useful format, so it was unexpected that certain insertion methods simply ignore all hooks. From this perspective, IMHO this behaviour feels like a gotcha, and almost even defeats the very purpose of hooks.

I can definitely understand a use case for wanting to initiate the store with data without firing hooks - but this feels like something you should explicitly express during the action (such as the suggested {raw: true} or similar), and not inherent behaviour you need to know to override or avoid.

In the interim, this note should be added to the documentation, because neither the Inserting Data nor the Lifecycle Hooks pages describe this behaviour, and I only learned about it from this issue after spending slightly too long debugging 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants