2.0.17 • Published 5 years ago

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

Weekly downloads
2
License
WTFPL
Repository
github
Last release
5 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

5 years ago

2.0.16

5 years ago

2.0.15

5 years ago

2.0.14

6 years ago

2.0.13

6 years ago

2.0.12

6 years ago

2.0.11

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

2.0.0-rc.14

6 years ago

2.0.0-rc.13

6 years ago

2.0.0-rc.12

6 years ago

2.0.0-rc.11

7 years ago

2.0.0-rc.10

7 years ago

2.0.0-rc.9

7 years ago

2.0.0-rc.8

7 years ago

2.0.0-rc.7

7 years ago

2.0.0-rc.6

7 years ago

2.0.0-rc.5

7 years ago

2.0.0-rc.4

7 years ago

2.0.0-rc.3

7 years ago

2.0.0-rc.2

7 years ago

2.0.0-next.2

7 years ago

2.0.0-next.1

7 years ago

2.0.0-next.0

7 years ago

2.0.0-rc.1

7 years ago

2.0.0-rc.0

7 years ago

1.0.0-alpha.11

7 years ago

1.0.0-alpha.10

7 years ago

1.0.0-alpha.9

7 years ago

1.0.0-alpha.8

7 years ago

1.0.0-alpha.7

7 years ago

1.0.0-alpha.6

7 years ago

1.0.0-alpha.5

7 years ago

1.0.0-alpha.4

7 years ago

1.0.0-alpha.3

7 years ago

1.0.0-alpha.2

7 years ago

1.0.0-alpha.1

7 years ago