Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

feat(nuxt): deep watch useCookie ref value by default #9664

Merged
merged 7 commits into from
Dec 19, 2022
Merged

feat(nuxt): deep watch useCookie ref value by default #9664

merged 7 commits into from
Dec 19, 2022

Conversation

xtoolkit
Copy link
Contributor

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

useCookie only change when .value update. we can use deep flag in watch and track all change.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codesandbox
Copy link

codesandbox bot commented Dec 12, 2022

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@vercel
Copy link

vercel bot commented Dec 12, 2022

@xtoolkit is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@xtoolkit
Copy link
Contributor Author

Sorry for my bad English. please rewrite document ...

packages/nuxt/src/app/composables/cookie.ts Show resolved Hide resolved
@@ -15,6 +15,7 @@ export interface CookieOptions<T = any> extends _CookieOptions {
decode?(value: string): T
encode?(value: T): string
default?: () => T | Ref<T>
watch?: boolean | 'deep' | 'shallow'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
watch?: boolean | 'deep' | 'shallow'
watch?: false | 'deep' | 'shallow'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think better keep boolean type. Because it maybe passed by variable.

export function useCookieTest(watch: boolean) {
  const test = useCookie('test', {}, {watch})
  const change = () => {test.value = 100}

  return {change}
}


Specifies the `boolean` or `string` value for [watch](https://vuejs.org/api/reactivity-core.html#watch) cookie ref data.

- `true` or `shallow` will watch cookie ref data.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- `true` or `shallow` will watch cookie ref data.
- `shallow` will watch cookie ref data.

@pi0
Copy link
Member

pi0 commented Dec 12, 2022

@danielroe Do you agree to making default behavior deep watching cookie value or any merits to keep it one level by default?

@danielroe
Copy link
Member

Agreed - I think deep behaviour is more intuitive. πŸ‘

@pi0 pi0 changed the title feat(nuxt): useCookie add deep watch option feat(nuxt): deep watch useCookie ref value by default Dec 12, 2022
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM ❀️

@pi0 pi0 merged commit 04c8625 into nuxt:main Dec 19, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe mentioned this pull request Jan 20, 2023
danielroe added a commit that referenced this pull request Jan 21, 2023
* feat(nuxt): useCookie add deep watch option

* docs(api): useCookie add deepWatch option

* feat(nuxt): useCookie change deepWatch to watch option

* boolean|shallow

* enable watch by default

* docs: fix example

* docs(api): update useCookie example

Co-authored-by: Pooya Parsa <pooya@pi0.io>
Co-authored-by: Daniel Roe <daniel@roe.dev>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants