Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knockout-decorators

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knockout-decorators - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

6

dist/knockout-decorators.d.ts

@@ -0,1 +1,2 @@

/// <reference types="knockout" />
export interface ComponentConstructor {

@@ -66,2 +67,7 @@ new (params?: any, element?: Node, templateNodes?: Node[]): any;

export declare function autobind(prototype: Object, key: string | symbol, desc: PropertyDescriptor): PropertyDescriptor;
/**
* Get internal ko.observable() for object property decodated by @observable
*/
export declare function unwrap(instance: Object, key: string | symbol): any;
export declare function unwrap<T>(instance: Object, key: string | symbol): KnockoutObservable<T>;
export as namespace KnockoutDecorators;

@@ -7,2 +7,6 @@ (function (global, factory) {

/**
* Copyright (c) 2016 Dmitry Panyushkin
* Available under MIT license
*/
var assign = ko.utils.extend;

@@ -329,2 +333,5 @@ var objectForEach = ko.utils.objectForEach;

}
function unwrap(instance, key) {
return getDescriptor(instance, key).get;
}

@@ -339,2 +346,3 @@ exports.component = component;

exports.autobind = autobind;
exports.unwrap = unwrap;

@@ -341,0 +349,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

2

dist/knockout-decorators.min.js

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("knockout")):"function"==typeof define&&define.amd?define(["exports","knockout"],t):t(e.KnockoutDecorators=e.KnockoutDecorators||{},e.ko)}(this,function(e,t){"use strict";function o(e,o,n,r){return void 0===r&&(void 0===n?"object"!=typeof o||o.constructor!==Object||"require"in o||"element"in o||(r=o,o=void 0):"object"==typeof n&&(r=n,n=void 0)),function(n){t.components.register(e,h({viewModel:n.length<2?n:{createViewModel:function(e,t){var o=t.element,r=t.templateNodes;return new n(e,o,r)}},template:o||"<!---->",synchronous:!0},r))}}function n(e){var t=e[w];return e.hasOwnProperty(w)||(e[w]=t=h({},t),g(t,function(e,o){t[e]=o.slice()})),t}function r(e,t){return e[t]||(e[t]=[])}function i(e){return e[E]||(e[E]=[])}function u(e,t,o){var n=e[w],r=n&&n[t];return r&&r.forEach(function(t){switch(t.type){case y.Extend:var n=t.value instanceof Function?t.value.call(e):t.value;o=o.extend(n);break;case y.Subscribe:var r=o.subscribe(t.value,e,t.event);t.dispose&&i(e).push(r)}}),o}function c(e){if(!e[S]){e[S]=!0;var t=e.dispose;e.dispose=function(){var e=this[E];if(e&&e.forEach(function(e){e.dispose()}),t)return t.apply(this,arguments)}}}function s(e,o){m(e,o,{configurable:!0,get:function(){var e=u(this,o,t.observable());return m(this,o,{configurable:!0,enumerable:!0,get:e,set:e}),e()},set:function(e){var n=u(this,o,t.observable());m(this,o,{configurable:!0,enumerable:!0,get:n,set:n}),n(e)}})}function a(e,o){var n=u(e,o,t.observableArray()),r=!1;m(e,o,{configurable:!0,enumerable:!0,get:n,set:function(e){e&&(j.forEach(function(t){return m(e,t,{configurable:!0,value:function(){if(r)return Array.prototype[t].apply(e,arguments);r=!0;var o=n[t].apply(n,arguments);return r=!1,o}})}),x.forEach(function(t){return m(e,t,{configurable:!0,value:function(){r=!0;var e=n[t].apply(n,arguments);return r=!1,e}})})),r=!0,n(e),r=!1}})}function f(e,t){m(e,t,{configurable:!0,get:function(){return a(this,t),this[t]},set:function(e){return a(this,t),this[t]=e}})}function l(e,o,n){var r=n||(n=_(e,o)),i=r.get,u=r.set;return n.get=function(){var e=t.pureComputed(i,this);return m(this,o,{configurable:!0,get:e,set:u}),e()},n}function b(e,o,n){function r(e,o,n){var r=(n||(n=_(e,o))).value;return n.value=function(){var e=this,o=k(arguments),n=t.computed(function(){return r.apply(e,o)});return u&&i(this).push(n),n},u&&c(e),n}var u;if("boolean"==typeof e&&void 0===o)return u=e,r;if("object"!=typeof e||void 0===o)throw new Error("Can not use @observer decorator this way");u=!0,r(e,o,n)}function p(e){return function(t,o){r(n(t),o).push({type:y.Extend,value:e})}}function d(e,t,o){return void 0===o&&(o=!0),function(i,u,s){var a,f,l=s||(s=_(i,u)),b=l.value,p=l.get;if("function"==typeof b){if("string"!=typeof e&&"symbol"!=typeof e)throw new Error("Subscription target should be a key in decorated ViewModel");a=e,f=b}else if("function"==typeof p)if("function"==typeof e)a=u,f=e;else{if("string"!=typeof e&&"symbol"!=typeof e)throw new Error("Subscription callback should be a function or key in decorated ViewModel");a=u,f=i[e]}return r(n(i),a).push({type:y.Subscribe,value:f,event:t,dispose:o}),o&&c(i),s}}function v(e,t,o){var n=o||(o=_(e,t)),r=n.value,i=n.configurable,u=n.enumerable;return{configurable:i,enumerable:u,get:function(){if(this===e)return r;var o=r.bind(this);return m(this,t,{configurable:!0,value:o}),o}}}var y,h=t.utils.extend,g=t.utils.objectForEach,m=Object.defineProperty.bind(Object),_=Object.getOwnPropertyDescriptor.bind(Object),k=Function.prototype.call.bind(Array.prototype.slice),w="undefined"!=typeof Symbol?Symbol("ko_decorators"):"__ko_decorators_",E="undefined"!=typeof Symbol?Symbol("ko_decorators_subscriptions"):"__ko_decorators_subscriptions_",S="undefined"!=typeof Symbol?Symbol("ko_decorators_disposable"):"__ko_decorators_disposable_";!function(e){e[e.Extend=0]="Extend",e[e.Subscribe=1]="Subscribe"}(y||(y={}));var j=["pop","push","reverse","shift","sort","splice","unshift"],x=["remove","removeAll","destroy","destroyAll","replace","subscribe"];e.component=o,e.observable=s,e.observableArray=f,e.computed=l,e.observer=b,e.extend=p,e.subscribe=d,e.autobind=v,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("knockout")):"function"==typeof define&&define.amd?define(["exports","knockout"],t):t(e.KnockoutDecorators=e.KnockoutDecorators||{},e.ko)}(this,function(e,t){"use strict";function o(e,o,n,r){return void 0===r&&(void 0===n?"object"!=typeof o||o.constructor!==Object||"require"in o||"element"in o||(r=o,o=void 0):"object"==typeof n&&(r=n,n=void 0)),function(n){t.components.register(e,g({viewModel:n.length<2?n:{createViewModel:function(e,t){var o=t.element,r=t.templateNodes;return new n(e,o,r)}},template:o||"<!---->",synchronous:!0},r))}}function n(e){var t=e[E];return e.hasOwnProperty(E)||(e[E]=t=g({},t),m(t,function(e,o){t[e]=o.slice()})),t}function r(e,t){return e[t]||(e[t]=[])}function i(e){return e[S]||(e[S]=[])}function u(e,t,o){var n=e[E],r=n&&n[t];return r&&r.forEach(function(t){switch(t.type){case h.Extend:var n=t.value instanceof Function?t.value.call(e):t.value;o=o.extend(n);break;case h.Subscribe:var r=o.subscribe(t.value,e,t.event);t.dispose&&i(e).push(r)}}),o}function c(e){if(!e[j]){e[j]=!0;var t=e.dispose;e.dispose=function(){var e=this[S];if(e&&e.forEach(function(e){e.dispose()}),t)return t.apply(this,arguments)}}}function s(e,o){_(e,o,{configurable:!0,get:function(){var e=u(this,o,t.observable());return _(this,o,{configurable:!0,enumerable:!0,get:e,set:e}),e()},set:function(e){var n=u(this,o,t.observable());_(this,o,{configurable:!0,enumerable:!0,get:n,set:n}),n(e)}})}function a(e,o){var n=u(e,o,t.observableArray()),r=!1;_(e,o,{configurable:!0,enumerable:!0,get:n,set:function(e){e&&(x.forEach(function(t){return _(e,t,{configurable:!0,value:function(){if(r)return Array.prototype[t].apply(e,arguments);r=!0;var o=n[t].apply(n,arguments);return r=!1,o}})}),O.forEach(function(t){return _(e,t,{configurable:!0,value:function(){r=!0;var e=n[t].apply(n,arguments);return r=!1,e}})})),r=!0,n(e),r=!1}})}function f(e,t){_(e,t,{configurable:!0,get:function(){return a(this,t),this[t]},set:function(e){return a(this,t),this[t]=e}})}function l(e,o,n){var r=n||(n=k(e,o)),i=r.get,u=r.set;return n.get=function(){var e=t.pureComputed(i,this);return _(this,o,{configurable:!0,get:e,set:u}),e()},n}function b(e,o,n){function r(e,o,n){var r=(n||(n=k(e,o))).value;return n.value=function(){var e=this,o=w(arguments),n=t.computed(function(){return r.apply(e,o)});return u&&i(this).push(n),n},u&&c(e),n}var u;if("boolean"==typeof e&&void 0===o)return u=e,r;if("object"!=typeof e||void 0===o)throw new Error("Can not use @observer decorator this way");u=!0,r(e,o,n)}function p(e){return function(t,o){r(n(t),o).push({type:h.Extend,value:e})}}function d(e,t,o){return void 0===o&&(o=!0),function(i,u,s){var a,f,l=s||(s=k(i,u)),b=l.value,p=l.get;if("function"==typeof b){if("string"!=typeof e&&"symbol"!=typeof e)throw new Error("Subscription target should be a key in decorated ViewModel");a=e,f=b}else if("function"==typeof p)if("function"==typeof e)a=u,f=e;else{if("string"!=typeof e&&"symbol"!=typeof e)throw new Error("Subscription callback should be a function or key in decorated ViewModel");a=u,f=i[e]}return r(n(i),a).push({type:h.Subscribe,value:f,event:t,dispose:o}),o&&c(i),s}}function v(e,t,o){var n=o||(o=k(e,t)),r=n.value,i=n.configurable,u=n.enumerable;return{configurable:i,enumerable:u,get:function(){if(this===e)return r;var o=r.bind(this);return _(this,t,{configurable:!0,value:o}),o}}}function y(e,t){return k(e,t).get}var h,g=t.utils.extend,m=t.utils.objectForEach,_=Object.defineProperty.bind(Object),k=Object.getOwnPropertyDescriptor.bind(Object),w=Function.prototype.call.bind(Array.prototype.slice),E="undefined"!=typeof Symbol?Symbol("ko_decorators"):"__ko_decorators_",S="undefined"!=typeof Symbol?Symbol("ko_decorators_subscriptions"):"__ko_decorators_subscriptions_",j="undefined"!=typeof Symbol?Symbol("ko_decorators_disposable"):"__ko_decorators_disposable_";!function(e){e[e.Extend=0]="Extend",e[e.Subscribe=1]="Subscribe"}(h||(h={}));var x=["pop","push","reverse","shift","sort","splice","unshift"],O=["remove","removeAll","destroy","destroyAll","replace","subscribe"];e.component=o,e.observable=s,e.observableArray=f,e.computed=l,e.observer=b,e.extend=p,e.subscribe=d,e.autobind=v,e.unwrap=y,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=knockout-decorators.min.js.map
{
"name": "knockout-decorators",
"version": "0.5.0",
"version": "0.6.0",
"description": "Decorators for use Knockout JS in TypeScript and ESNext environments",

@@ -14,3 +14,3 @@ "main": "dist/knockout-decorators.js",

"build-typings": "tsc -p tsconfig.typings.json && shx rm -rf __temp && npm run fix-typings",
"fix-typings": "shx cat src/knockout-decorators.d.ts.tmpl >> dist/knockout-decorators.d.ts",
"fix-typings": "shx cat src/knockout-decorators.d.ts.tmpl >> dist/knockout-decorators.d.ts",
"test": "jest --no-cache"

@@ -17,0 +17,0 @@ },

@@ -42,4 +42,8 @@ # Knockout Decorators

* [@component](#knockout-decorators-component)
* [unwrap](#knockout-decorators-unwrap)
[Work with KnockoutValidation](#knockout-decorators-validation)
[Usage without module loaders](#knockout-decorators-without-loaders)
#### <a name="knockout-decorators-observable"></a> @observable

@@ -289,2 +293,45 @@ Property decorator that creates hidden `ko.observable` with ES6 getter and setter for it

<br>
#### <a name="knockout-decorators-unwrap"></a> unwrap
Get internal `ko.observable()` for property decodated by `@observable`
```js
unwrap(instance: Object, key: string | symbol): any;
unwrap<T>(instance: Object, key: string | symbol): KnockoutObservable<T>;
```
| Argument | Default | Description |
|:---------|:--------|:-------------------------------|
| instance | | Decorated class instance |
| key | | Name of `@observable` property |
<a name="knockout-decorators-validation"></a>
KnockoutValidation example
```js
class MyViewModel {
@extend({ required: "MyField is required" })
@observable myField = "";
checkMyField() {
alert("MyField is valid: " + unwrap(this, "myField").isValid());
}
// pass `unwrap` function to data-bindings
unwrap(key: string) {
return unwrap(this, key);
}
}
```
```html
<div>
<input type="text" data-bind="value: myField"/>
<button data-bind="click: checkMyField">check</button>
<p data-bind="validationMessage: unwrap('myField')"></p>
</div>
```
<br>
### <a name="knockout-decorators-without-loaders"></a>
### Usage without module loaders (in global scope)

@@ -291,0 +338,0 @@ __layout.html__

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc