2.0.17 • Published 4 years ago

@profiscience/knockout-contrib-router-plugins-with v2.0.17

Weekly downloads
2
License
WTFPL
Repository
github
Last release
4 years ago

router.plugins.with

Version Dependency Status Peer Dependency Status Dev Dependency Status Downloads

Allows extending the context for a route with arbitrary data

Usage

import { Route, withRoutePlugin } from '@profiscience/knockout-contrib'

Route.usePlugin(withRoutePlugin)

// Sync
new Route('/', {
  with: {
    myAdditionalProp: true,
  },
})

// Accessor
new Route('/', {
  with: (ctx) => {
    // synchronous
    return {
      myAdditionalProp: true,
    }

    // async via promises
    return Promise.resolve({
      myAdditionalProp: true,
    })
  },
})

Now, in the viewModel (as well as any subsequent middleware), ctx.myAdditionalProp will be true.

NOTE: If you're using TypeScript, it's worth noting that the return type is strongly typed. The properties it adds must be defined on the IContext interface, or cast as any.

e.g.

declare module '@profiscience/knockout-contrib-router' {
  interface IContext {
    myAdditionalProp?: boolean
  }
}

// ...or...

new Route('/', {
  with: {
    myAdditionalProp: true,
  } as any,
})
2.0.17

4 years ago

2.0.16

4 years ago

2.0.15

4 years ago

2.0.14

4 years ago

2.0.13

4 years ago

2.0.12

4 years ago

2.0.11

4 years ago

2.0.10

4 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

2.0.0-rc.14

5 years ago

2.0.0-rc.13

5 years ago

2.0.0-rc.12

5 years ago

2.0.0-rc.11

5 years ago

2.0.0-rc.10

6 years ago

2.0.0-rc.9

6 years ago

2.0.0-rc.8

6 years ago

2.0.0-rc.7

6 years ago

2.0.0-rc.6

6 years ago

2.0.0-rc.5

6 years ago

2.0.0-rc.4

6 years ago

2.0.0-rc.3

6 years ago

2.0.0-rc.2

6 years ago

2.0.0-next.2

6 years ago

2.0.0-next.1

6 years ago

2.0.0-next.0

6 years ago

2.0.0-rc.1

6 years ago

2.0.0-rc.0

6 years ago

1.0.0-alpha.11

6 years ago

1.0.0-alpha.10

6 years ago

1.0.0-alpha.9

6 years ago

1.0.0-alpha.8

6 years ago

1.0.0-alpha.7

6 years ago

1.0.0-alpha.6

6 years ago

1.0.0-alpha.5

6 years ago

1.0.0-alpha.4

6 years ago

1.0.0-alpha.3

6 years ago

1.0.0-alpha.2

6 years ago

1.0.0-alpha.1

6 years ago