@profiscience/knockout-contrib-model-mixins-query
TypeScript icon, indicating that this package has built-in type declarations

1.1.21 • Public • Published

model.mixins.query

This package is intended to be consumed via the @profiscience/knockout-contrib metapackage

Adds a .query property using the query package for persistent, stateless data model params.

In other words, initializes data model params via the querystring, and mirrors changes so that the same query will be applied if the page is reloaded. Useful for making bookmark-able pages.

See the query package for more details.

Usage

import {
  DataModelConstructorBuilder,
  QueryMixin,
} from '@profiscience/knockout-contrib'

class MyDataModel extends DataModelConstructorBuilder.Mixin(
  QueryMixin(
    { someQuerystringParameter: '' } /* Query options (see query package) */,
    'my-data-model' /* (optionally) supply a query group */
  )
)<any> {}

const model = new MyDataModel()

// if querystring contains `?someQuerystringParameter=foo`
model.query.someQuerystringParameter() === 'foo'

// update querystring to `?someQuerystringParameter=bar`
model.query.someQuerystringParameter('bar')

// query params are mirrored on `.params`, so it plays well will mixins
// that follow the correct conventions w/o additional buy in
model.params.someQuerystringParameter()

Readme

Keywords

none

Package Sidebar

Install

npm i @profiscience/knockout-contrib-model-mixins-query

Weekly Downloads

6

Version

1.1.21

License

WTFPL

Unpacked Size

28.7 kB

Total Files

12

Last publish

Collaborators

  • dorgeron
  • barsh