Whisrambol
Whisrambol

Reputation: 3

Javascript svelte.js

Many thanks about this piece of code.

export const page;

router('/access', () =>
    import('./views/access.svelte').then(
    module => page.set({ component: module.default })
    )
);

Upvotes: 0

Views: 120

Answers (1)

Christian
Christian

Reputation: 1260

  • page in import router from 'page' most likely refers to page.js, a JavaScript router (that doesn't have any Svelte dependency)
  • module.default refers to the default export of the file that is passed as the first argument to the import() function. This file would be './views/dashboard.svelte' in
    router('/dashboard', () =>
        import('./views/dashboard.svelte').then(
            module => page.set({ component: module.default })
        )
    );
    
    As all the imported files are Svelte components, the default export would be the component itself.
  • Why props are defined as empty I can't tell. But possibly, none of the components specified in import(/*component path here*/, /*more code here*/) requires any props.

Also, note that, although initially the page store is initialized with an object that has both, a component and props field, the page store's value is subsequently overwritten with an object that just has the component field (at all the calls to page.set()).

Upvotes: 2

Related Questions