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

Dispatch event when firing routes #2080

Merged
merged 3 commits into from
Nov 16, 2018
Merged

Dispatch event when firing routes #2080

merged 3 commits into from
Nov 16, 2018

Commits on Jun 20, 2018

  1. Dispatch event when firing routes

    It is especially neat when importing the scripts from the parent theme in a child theme. In one of my themes I do it like this:
    
    ```js
    // routes.js
    import home from './routes/home'
    
    export default {
        home: {
          init() {
            console.log('Home route fired.')
          }
        }
    }
    ```
    
      ```js
    // main.js
    /**
     * Parent Themes Script
     */
    import '../../../../core-theme/resources/assets/scripts/main';
    
    /**
     * Internal modules
     */
    import routes from './routes'
    
    /**
     * Hook in to the parent themes router
     */
    document.addEventListener('routed', e => {
      let route = e.detail.route,
        fn = e.detail.fn;
    
      if (routes[route] && typeof routes[route][fn] === 'function') {
        routes[route][fn]();
      }
    });
    ```
    tormjens committed Jun 20, 2018
    Configuration menu
    Copy the full SHA
    8f039f1 View commit details
    Browse the repository at this point in the history
  2. Rename to event

    tormjens committed Jun 20, 2018
    Configuration menu
    Copy the full SHA
    2af688c View commit details
    Browse the repository at this point in the history
  3. Fix comma dangle lint error

    tormjens committed Jun 20, 2018
    Configuration menu
    Copy the full SHA
    2d9b9d1 View commit details
    Browse the repository at this point in the history