How to use the @vue/composition-api.reactive function in @vue/composition-api

To help you get started, we’ve selected a few @vue/composition-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github metaspace2020 / metaspace / metaspace / webapp / src / components / RichText / RichTextArea.tsx View on Github external
setup(props, { emit, slots }) {
    const state = reactive({
      editor: useEditor({
        content: props.content,
        onUpdate: (content) => emit('update', content),
      }),
    })

    const { editor } = state

    return () => (
      <div class="sm-RichText sm-RichTextArea relative">
        {slots.label &amp;&amp; <label> { editor.focus() }}&gt;{slots.label()}</label>}
        </div>
github metaspace2020 / metaspace / metaspace / webapp / src / modules / MolecularDatabases / DatabasesTable.tsx View on Github external
setup(props) {
    const state = reactive({
      showUploadDialog: false,
    })

    const { result, loading, refetch } = useQuery(
      getGroupDatabasesQuery,
      { groupId: props.groupId },
      { fetchPolicy: 'no-cache' },
    )

    onBeforeMount(refetch)

    const onDialogClose = () => {
      state.showUploadDialog = false
    }

    const onUploadComplete = () => {
github LinusBorg / composition-api-demos / src / composables / use-promise.js View on Github external
export default function usePromise(fn) {
  if (!fn) {
    throw new Error(
      `[usePromise]: 1st argument is required (must be a function)`
    )
  }

  if (typeof fn !== 'function') {
    throw new Error(
      `[usePromise]: argument has to be function, but received ${typeof fn}`
    )
  }
  const state = reactive({
    loading: false,
    error: null,
    result: null,
  })

  let lastPromise
  const use = async (...args) => {
    state.error = null
    state.loading = true
    const promise = (lastPromise = fn(...args))
    try {
      const result = await promise
      if (lastPromise === promise) {
        state.result = result
      }
    } catch (e) {
github kiraka / annict-web / app / frontend / javascript / v3 / components / LikeButton.vue View on Github external
setup(props, _context) {
      const state = reactive({
        likesCount: props.initLikesCount,
        isLiked: props.initIsLiked,
        isLoading: false,
      })

      let likeMutation = null
      let unlikeMutation = null
      if (props.resourceName === 'WorkRecord') {
        likeMutation = new LikeWorkRecordMutation({ workRecordId: props.resourceId })
        unlikeMutation = new UnlikeWorkRecordMutation({ workRecordId: props.resourceId })
      }

      const toggleLike = async () => {
        if (!props.isSignedIn) {
          ($('.c-sign-up-modal') as any).modal('show')
          return
github kiraka / annict-web / app / frontend / javascript / v3 / components / pages / WorkDetail.vue View on Github external
setup(props, context) {
      const state = reactive({
        work: null,
        vodChannels: [],
        breadcrumbItems: [],
      })

      const removeCommentGuard = (event) => {
        $(event.target).parents('.p-work-records-show__content').removeClass('c-comment-guard')
      }

      onMounted(async () => {
        const [work, vodChannels] = await Promise.all([
          new FetchWorkQuery({ workId: props.workId }).execute(),
          new FetchVodChannelsQuery().execute()
        ])
        state.work = work
        state.vodChannels = vodChannels.map(vodChannel => {
github PECE-project / drupal-pece / src / front / components / DarkTheme.vue View on Github external
setup () {
    const state = reactive({ darkTheme: false })

    onMounted(() => {
      state.darkTheme = window.getComputedStyle(document.documentElement).getPropertyValue('content') === 'dark' ||
        !!localStorage.getItem('darkTheme') ||
        false
    })

    function toggleDarkTheme () {
      state.darkTheme = !state.darkTheme
      if (state.darkTheme) {
        return localStorage.setItem('darkTheme', 'on')
      }
      localStorage.removeItem('darkTheme')
    }

    return {
github metaspace2020 / metaspace / metaspace / webapp / src / modules / UserProfile / GroupsTable.tsx View on Github external
setup(props) {
    const rows = computed(() =&gt; getRows(props.currentUser))
    const state = reactive({
      showTransferDatasetsDialog: false,
      invitingGroup: null,
    })

    async function handleAcceptTransferDatasets(selectedDatasetIds: string[]) {
      try {
        await apolloClient.mutate({
          mutation: acceptGroupInvitationMutation,
          variables: { groupId: state.invitingGroup!.id },
        })
        if (selectedDatasetIds.length &gt; 0) {
          await apolloClient.mutate({
            mutation: importDatasetsIntoGroupMutation,
            variables: { groupId: state.invitingGroup!.id, datasetIds: selectedDatasetIds },
          })
        }
github metaspace2020 / metaspace / metaspace / webapp / src / components / RichText / RichText.tsx View on Github external
setup(props) {
    const state = reactive({
      editor: useEditor({
        extensions: [
          new OnEscape(() => {
            state.editing = false
            state.editor.blur()
          }),
        ].concat(
          props.placeholder ? new Placeholder({
            emptyNodeText: props.placeholder,
            emptyNodeClass: 'sm-RichText-placeholder',
            showOnlyWhenEditable: false,
          }) : [],
        ),
        editable: !props.readonly,
        content: props.content,
        onUpdate: async(content: string) => {
github metaspace2020 / metaspace / metaspace / webapp / src / modules / App / CookieBanner.tsx View on Github external
setup() {
    const state = reactive({
      agreed: get(cookieKey) === cookieValue,
    })

    const agree = () =&gt; {
      set(cookieKey, cookieValue)
      state.agreed = true
    }

    return () =&gt; (
      state.agreed
        ? null
        : <div style="z-index: 999" class="fixed bottom-0 left-0 right-0 bg-body text-white leading-6 py-1 text-sm">
          <button class="button-reset float-right cursor-pointer mx-1 h-6">
            
          </button>
          <p class="m-0 text-center px-2"></p></div>
github PECE-project / drupal-pece / src / front / components / ListFilter.vue View on Github external
setup (_, { emit }) {
    const state = reactive({
      filter: []
    })

    return {
      ...toRefs(state)
    }
  }
}