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

feat(runtime-core): api to detach watchers and computed values from component lifecycle #2185

Closed
wants to merge 1 commit into from

Conversation

unbyte
Copy link
Contributor

@unbyte unbyte commented Sep 21, 2020

related: #1532

watch and wathEffect

option lifecycle: 'static' | 'instance', default to instance

with the static lifecycle, effects created inside a setup will still live after the component instance unmounted.

const stop = watchEffect(()=>{
        // ...
      }, { lifecycle: 'static' })

// in dev mode, a warn will be output to remind users to stop effects manually

staticComputed

in order to not break current behavior, provide a new api staticComputed which can create computed values of static lifecycle.

users can stop effects manually by call stop method on computed value

const someValue = ref(0)
const val = staticComputed(() => someValue.value + 1)
val.value // 1
val.stop() // stop the effect inside computed value

close #1532

@ZhangJian-3ti
Copy link
Contributor

ZhangJian-3ti commented Sep 21, 2020

vuejs/rfcs#212
According to this RFC, I think it's a better way to resolve such issues.

@unbyte
Copy link
Contributor Author

unbyte commented Sep 21, 2020

@ZhangJian-3ti you are right 😁

@unbyte unbyte closed this Sep 21, 2020
@unbyte unbyte reopened this Sep 21, 2020
@unbyte
Copy link
Contributor Author

unbyte commented Sep 21, 2020

wait, this rfc doesn't point out the problem that this PR wants to solve. I will keep it open until the discussion is clear.

@unbyte unbyte closed this Sep 22, 2020
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.

Option to not stop watch when component is unmounted
2 participants