knockout.getset
Simple library to start using this.property = true;
instead of this.property(true);
for observables in Knockout.
Installation
Install from bower
:
bower install knockout-getset --save
or npm
:
npm install knockout.getset --save
Compatibility
Internet Explorer 9+ and literaly anything else. For more information consult this table.
Documentation
Observable
To define an observable you need:
var viewmodel = {} initialValue = 1;ko;
Then observableProperty
will be available to modification in viewModel
object:
viewmodelobservableProperty = 1;viewmodelobservableProperty; //1 viewmodelobservableProperty = 5;viewmodelobservableProperty; //5
If you want to register your own subscriptions with gsObservable
:
ko ; viewmodelobservableProperty = 5;//I've been changed to 5
Observable Array
To define an observable array you need:
ko; viewmodelobservableArray; //[]
Computed
To define a computed you need:
ko; viewmodelcomputed; //"I'm computed!"
Example on using of computed with observables:
ko; ko; viewmodeltitle; "Mr. Peter Griffin" viewmodelname = 'Brian Griffin';viewmodeltitle; "Mr. Brian Griffin"
Simple objects
Since there is no observables in viewmodel then we can simply skip a 'ko.toJS' or any other unwrap routine. In example:
ko; ko; JSON;//'{ "name":"Peter Griffin", "title":"Mr. Peter Griffin" }'