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.6.0 to 0.7.0

4

dist/knockout-decorators.d.ts

@@ -49,4 +49,4 @@ /// <reference types="knockout" />

*/
export declare function observer(autoDispose: boolean): MethodDecorator;
export declare function observer(prototype: Object, key: string | symbol, desc: PropertyDescriptor): PropertyDescriptor;
export declare function reaction(autoDispose: boolean): MethodDecorator;
export declare function reaction(prototype: Object, key: string | symbol, desc: PropertyDescriptor): PropertyDescriptor;
/**

@@ -53,0 +53,0 @@ * Apply extenders to decorated @observable

@@ -221,14 +221,14 @@ (function (global, factory) {

*/
function observer(prototypeOrAutoDispose, key, desc) {
function reaction(prototypeOrAutoDispose, key, desc) {
var autoDispose;
if (typeof prototypeOrAutoDispose === "boolean" && key === void 0) {
autoDispose = prototypeOrAutoDispose; // @observer(false)
autoDispose = prototypeOrAutoDispose; // @reaction(false)
return decorator; // onSomethingChange() {}
}
else if (typeof prototypeOrAutoDispose === "object" && key !== void 0) {
autoDispose = true; // @observer
autoDispose = true; // @reaction
decorator(prototypeOrAutoDispose, key, desc); // onSomethingChange() {}
}
else {
throw new Error("Can not use @observer decorator this way");
throw new Error("Can not use @reaction decorator this way");
}

@@ -341,3 +341,3 @@ function decorator(prototype, key, desc) {

exports.computed = computed$1;
exports.observer = observer;
exports.reaction = reaction;
exports.extend = extend;

@@ -344,0 +344,0 @@ exports.subscribe = subscribe;

@@ -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,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})});
!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 @reaction 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.reaction=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.6.0",
"version": "0.7.0",
"description": "Decorators for use Knockout JS in TypeScript and ESNext environments",

@@ -5,0 +5,0 @@ "main": "dist/knockout-decorators.js",

@@ -38,3 +38,3 @@ # Knockout Decorators

* [@computed](#knockout-decorators-computed)
* [@observer](#knockout-decorators-observer)
* [@reaction](#knockout-decorators-reaction)
* [@extend](#knockout-decorators-extend)

@@ -114,7 +114,7 @@ * [@subscribe](#knockout-decorators-subscribe)

#### <a name="knockout-decorators-observer"></a> @observer
#### <a name="knockout-decorators-reaction"></a> @reaction
Replace original method with factory that produces `ko.computed` from original method
```js
@observer
@observer(autoDispose: boolean)
@reaction
@reaction(autoDispose: boolean)
```

@@ -125,3 +125,3 @@ | Argument | Default | Description |

Method that decorated with `@observer` evaluates once when explicitely invoked (this call creates hidden `ko.computed`)
Method that decorated with `@reaction` evaluates once when explicitely invoked (this call creates hidden `ko.computed`)
and every times when it's observable (or computed) dependencies are changed.

@@ -144,3 +144,3 @@

@observer async onRoute(blogId: ko.Observable<number>) {
@reaction async onRoute(blogId: ko.Observable<number>) {
const resp = await fetch(`/blog/${ blogId() }/post/${ this.postId }`);

@@ -147,0 +147,0 @@ this.pageData = await resp.json();

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