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

New feature ideas #308

Open
719media opened this issue Jul 20, 2023 · 2 comments
Open

New feature ideas #308

719media opened this issue Jul 20, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@719media
Copy link
Contributor

719media commented Jul 20, 2023

Hey,
Excited for a new version of this library with some possible improvements. Just wanted to make a few recommendations:

  1. A "non-mixin" way of doing $keepSharedElementAlive. For example:
import { ref, onMounted, onActivated } from 'vue'

// by convention, composable function names start with "use"
export function useSharedElementKeepAlive() {
  // state encapsulated and managed by the composable
  const sharedElementTriggers = ref([]);
  const sharedElementFirstRender = ref(true);

  onMounted(() => {
    sharedElementTriggers.value.forEach((trigger) => {
      return trigger();
    });
  });

  onActivated(() => {
    if (sharedElementFirstRender.value) {
      return (sharedElementFirstRender.value = false);
    }
    sharedElementTriggers.value.forEach((trigger) => {
      return trigger();
    });
  });

  function keepSharedElementAlive(trigger) {
    sharedElementTriggers.value.push(trigger);
  }

  // expose managed state as return value
  return {
    keepSharedElementAlive,
  };
}

Could then be used in setup() more nicely. Keep in mind there is a potential bug with this implementation (that also exists in the current mixin as well): vuejs/core#7276

  1. A way to use this library without vue-router

  2. A way to enable/disable by parameter on the directive (e.g. v-shared-element="{disabled: true}")

@719media
Copy link
Contributor Author

One more clarification to the disabled parameter would be handling onUpdated hook as well (in case duration, argument id, etc. changes... obviously having disabled: true doesn't make much sense if it isn't dynamic)

@justintaddei
Copy link
Owner

I really like these ideas. I can't do much with it right now but as soon as I can get some free time I will look more into it as well as Nuxt 3 support

@justintaddei justintaddei added the enhancement New feature or request label Sep 6, 2023
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

2 participants