Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Make directives available to all components within a render tree #6732

Copy link
Copy link
Closed
@trainiac

Description

@trainiac
Issue body actions

What problem does this feature solve?

If you have a directive that relies on a piece of user data (e.g. language), in server side rendering you need to be able to create a new directive per request.

const getTranslateDirective = lang => ( {
  bind () {
    // access to lang
  },
  update () {
    // access to lang
  }
})

const translate = getTranslateDirective(() => parsedLangHeader.language)

// PROBLEM - this sets translate a directive globally across reqeusts
Vue.directive('translate', translate)

However this is a problem because when you call Vue.directive('translate', translate) this changes the translate directive across ALL requests.

What does the proposed API look like?

What is needed is a way to make directives available to a component and all of it's children components

const getTranslateDirective = lang => ( {
  bind () {
    // access to lang
  },
  update () {
    // access to lang
  }
})

const translate = getTranslateDirective(() => parsedLangHeader.language)

new Vue({
  directives: {
    translate: {
      module: translate,
      provide: true // Makes the directive available to this component and all of it's children.
    }
  }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.