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

refactor(useMediaControls): Deprecate options that can simply be set as attributes #514

Merged
merged 7 commits into from
May 24, 2021

Conversation

cawa-93
Copy link
Member

@cawa-93 cawa-93 commented May 15, 2021

If you change the volume or muted values by native controls (or in devtools) it does not effect reactive variables. Here is a demonstration.

@cawa-93 cawa-93 requested a review from wheatjs May 15, 2021 07:21
wheatjs
wheatjs previously approved these changes May 15, 2021
@wheatjs
Copy link
Member

wheatjs commented May 15, 2021

Good catch, I actually noticed these issues recently but hadn't had the chance to go back and fix them. Thanks for picking up my slack on these 😄

@cawa-93 cawa-93 marked this pull request as draft May 15, 2021 07:28
@wheatjs
Copy link
Member

wheatjs commented May 15, 2021

Maybe consider adding a check if el exists to get rid of the error

@cawa-93
Copy link
Member Author

cawa-93 commented May 15, 2021

I hastened with it. How could we update the mute that comes from options? My first think was:

    if (options.muted !== undefined && isRef(options.muted))
      options.muted.value = (unref(target))!.muted

But TS prompts me that options.muted.value is readonly.

UseMediaControlsOptions.muted: Ref<boolean> | ComputedRef<boolean>

@wheatjs
Copy link
Member

wheatjs commented May 15, 2021

Hmm, I'll take a look tomorrow if you don't figure it out before then.

@cawa-93
Copy link
Member Author

cawa-93 commented May 17, 2021

What if return new muted value? In the same way as all other parameters return.

{
  muted // <-- Reactive value
} = useMediaControls(video, {
  muted: MaybeRef<boolean>, // <-- Initial value
}

@wheatjs
Copy link
Member

wheatjs commented May 17, 2021

Hmm, maybe we should just remove the volume and muted objects from the initial parameters all together? Maybe things like muted and volume should just be returned from the object like you suggested. I feel like having the initial parameters and also returned might be over complicating it. I think what would be best is things that have a 2 way data flow, like volume, currentTime, and muted are returned from the function while things that have a one-way data flow like poster should be treated as configuration options.

@cawa-93
Copy link
Member Author

cawa-93 commented May 18, 2021

Sounds good.

How about to deprecate one-way data that can be set by <video> attibutes and does't have any "reactive logic": loop, controls, preload, autoplay, poster, playsInline and autoPictureInPicture.

Don't

const poster = ref('[link to poster image]')
const {} = useMediaControls(target, {
  poster,
})

Do

<template>
  <video :poster="poster">
</template>

<script setup>
const poster = ref('[link to poster image]')

const {} = useMediaControls(target, {})
</script>

What do you thinks?

UPD.
At first glance, this looks like a compatible change, because after v4.11 we can already use the attributes to configure <video>. So all we have to do is add an deprecation message and remove that options in v5.0

@wheatjs
Copy link
Member

wheatjs commented May 18, 2021

Hmm yeah that seems like a decent idea, doing less might be a better idea in this case. We mostly want to simplify that more difficult to control portions of the video element which I think we already do pretty well. So some of the simpler options like poster can be removed from the function in favor of just using the element attributes.

@cawa-93
Copy link
Member Author

cawa-93 commented May 18, 2021

@wheatjs Please review how I create deprecation message. If all goes well, I'll do the same for the rest of the options I talked about earlier.

@wheatjs
Copy link
Member

wheatjs commented May 19, 2021

@wheatjs Please review how I create deprecation message. If all goes well, I'll do the same for the rest of the options I talked about earlier.

Sure thing, sorry for the delay, I'll review this sometime today 😄

@antfu
Copy link
Member

antfu commented May 19, 2021

How about to deprecate one-way data that can be set by <video> attibutes and does't have any "reactive logic": loop, controls, preload, autoplay, poster, playsInline and autoPictureInPicture.

Yeah, that sounds better to me to be as well. User could also use v-bind when they want to provide them altogether as an object.

@wheatjs
Copy link
Member

wheatjs commented May 20, 2021

@wheatjs Please review how I create deprecation message. If all goes well, I'll do the same for the rest of the options I talked about earlier.

The deprecation messages look good to me. Once you add them for the rest of the functions we can do another review and make sure everything works like expected

* `poster`
* `autoplay`
* `preload`
* `loop`
* `controls`
* `playsinline`
* `autoPictureInPicture`
@cawa-93
Copy link
Member Author

cawa-93 commented May 20, 2021

I don't changed demo in last commit for checking backward compatibility

@cawa-93 cawa-93 requested a review from wheatjs May 20, 2021 06:57
wheatjs
wheatjs previously approved these changes May 20, 2021
Copy link
Member

@wheatjs wheatjs left a comment

Choose a reason for hiding this comment

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

Nice job with the console warns as well, it looks good too me

@cawa-93 cawa-93 changed the title useMediaControls: Add volumechange event listener useMediaControls: Deprecate options that can simply be set as attributes May 20, 2021
@cawa-93 cawa-93 marked this pull request as ready for review May 20, 2021 08:19
@antfu
Copy link
Member

antfu commented May 21, 2021

I was trying to avoid console logs in VueUse whenever possible. Since we don't have different builds for dev and prod, using consoles would also ships extra bits and hard-coded strings to production. Which are also out of users' control

I would suggest to mark the API depredated on type level but keep the behavior the same, and then we can remove the code in major versions later

@wheatjs
Copy link
Member

wheatjs commented May 21, 2021

Nice job with the console warns as well, it looks good too me

Sorry I forgot about us trying to avoid console logs 😅

@wheatjs
Copy link
Member

wheatjs commented May 22, 2021

This is only slightly relevant to this PR, but it seems like my links for the subtitles expired for the demo so if you want you can add them locally maybe? Otherwise we can do it in another PR

Here are the gists for the subtitles:

English https://gist.github.com/wheatjs/a85a65a82d87d7c098e1a0972ef1f726
French https://gist.github.com/wheatjs/38f32925d20c683bf77ba33ff737891b

@antfu antfu changed the title useMediaControls: Deprecate options that can simply be set as attributes refactor(useMediaControls): Deprecate options that can simply be set as attributes May 24, 2021
@antfu antfu merged commit bb40e3d into vueuse:main May 24, 2021
antfu pushed a commit that referenced this pull request May 25, 2021
…as attributes (#514)

* useMediaControls: Add `volumechange` event listener

* fix: `mute` returned

* feat: Deprecate video options:
* `poster`
* `autoplay`
* `preload`
* `loop`
* `controls`
* `playsinline`
* `autoPictureInPicture`

* fix: Fix deprecated behaviour in demo

* fix: Remove deprecated usage from doc

* refactor: More polite messages

* fix: Remove `console.warn`s
@cawa-93 cawa-93 deleted the cawa-93-volumechange-event branch May 25, 2021 09:29
antfu added a commit that referenced this pull request Jun 6, 2021
* feat(useTransition): support for vectors (#376)

* refactor(useTransition): cleaning up (#385)

* refactor(useWebWorkerFn): Small doc and type improvements (#382)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>

* feat: pwa reload prompt

* chore: update docs

* refactor(useWebWorkerFn): Small doc and type improvements (#382)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>

* chore: update docs

* test: simpilfy tests for useTransition

* chore: fix tests

* feat(useTransition): support for delayed transitions (#386)

* feat(useTransition): support for disabled transitions (#436)

* feat!: introduce `controls` option

* chore: update

* chore: update

* refactor(useRafFn): remove depreacted APIs

* chore: enabled tests for next branch

* fix(useFetch)!: allow setting response type before doing request (#454)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>

* chore: resolve conflicts

* feat(useMediaControls): expose source types (#495)

* fix(useMediaControls): Removes tracks that have been inserted in html (#493)

* chore: release v4.9.3

* fix(usePermission): tolerate error on FireFox

* fix(useDevicesList): treat as premssion granted after getUserMedia

* chore: release v4.9.4

* chore: fix typo (#502)

* feat(useWebSocket): add immediate option (#503)

* feat(useAxios): bring API into line with useFetch (#499)

* feat(createEventHook): new function (#497)

* chore: release v4.10.0

* fix(useMediaControls): Doesn't rewrite default media properties (#500)

* feat(useMediaControls): add error event (#509)

* feat(useStorage): optimize event handling logic (#505)

* feat(useFetch): add afterFetch option, onFetchResponse, and onFetchError (#506)

* feat(useWebWoker): return worker (#507)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>

* fix: Change `onMediaError` to `onSourceError` (#510)

* feat(onClickOutside): default to just pointerDown (#508)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Co-authored-by: sibbng <sibbngheid@gmail.com>

* chore: update docs

* chore: release v4.11.0

* fix(onClickOutside): duplicate code (#519)

Co-authored-by: Nurettin Kaya <sibbngheid@gmail.com>

* feat(createEventHook): added interface (#531)

* feat(createEventHook): added interface

* added types for EventHookOn, EventHookOff, and EventHook trigger

* feat(useStorage): allow custom serializer (#528)

* feat(useStorage): allow custom serializer

* update test

* refactor(useMediaControls): Deprecate options that can simply be set as attributes (#514)

* useMediaControls: Add `volumechange` event listener

* fix: `mute` returned

* feat: Deprecate video options:
* `poster`
* `autoplay`
* `preload`
* `loop`
* `controls`
* `playsinline`
* `autoPictureInPicture`

* fix: Fix deprecated behaviour in demo

* fix: Remove deprecated usage from doc

* refactor: More polite messages

* fix: Remove `console.warn`s

* chore: release v4.11.1

* refactor!: remove deprecated apis

* chore: add next tag

* chore: release v5.0.0-beta.1

* feat: introduce `components` & `directives` (#486)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>

* docs: re-organize

* chore: fix lint

* docs: about components

* chore: include directives

* chore: release v5.0.0-beta.2

* chore: rollback jest

* chore: fix docs build

* docs: readme for components

* docs: add @vueuse/gesture

* chore: ship indexes.json

* chore: release v5.0.0-beta.3

* feat(typedef): add return typedefs (#543) (#544)

* refactor!: change publish strcture and support submodules, close #469

* chore: cleanup stories.tsx

* docs: update docs about submodules

* chore: fix docs

* chore: release v5.0.0-beta.4

* chore: update lock

* chore: release v5.0.0-beta.5

* chore: update deps and extend publish memory

* refactor: remove `useDeviceLight`

* chore: update

* chore: fix tests

* chore: release v5.0.0-beta.7

* refactor(useWebSocket)!: change immediate default for 5.0.0 (#545)

* feat(useIpcRenderer): new add-one & new functions (#547)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>

* chore: update deps

* chore: release v5.0.0-beta.8

* chore: fix docs build

* chore(usePointerSwipe): fix typo (#557)

* fix(useAuth): now reqiures the auth instance, close #538

* chore: update deps

* docs(biSyncRef): fix console output comment (#555)

* docs: removed deprecated value from example (#556)

* docs(guidlines): added guidelines (#535)

* docs: update guidelines

* chore: update guidelines

Co-authored-by: Scott Bedard <scottbedard@users.noreply.github.com>
Co-authored-by: Fabian <donskelle@googlemail.com>
Co-authored-by: Ismail Gjevori <isgjevori@protonmail.com>
Co-authored-by: Alex Kozack <cawa-93@users.noreply.github.com>
Co-authored-by: Shinigami <chrissi92@hotmail.de>
Co-authored-by: wheat <jacobrclevenger@gmail.com>
Co-authored-by: sibbng <sibbngheid@gmail.com>
Co-authored-by: JserWang <jserwang@gmail.com>
Co-authored-by: Pig Fang <g-plane@hotmail.com>
Co-authored-by: ArcherGu <34826812+ArcherGu@users.noreply.github.com>
Co-authored-by: Ilya Komichev <hello@ilko.me>
Co-authored-by: Daiki Ojima <daiking.ca2@gmail.com>
Co-authored-by: Manaus <manaustransez@hotmail.com>
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.

None yet

3 participants