New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

signal-chain

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

signal-chain - npm Package Compare versions

Comparing version 0.10.1 to 0.10.2

3

dist/signal/array.d.ts

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

import { PrimitiveSignal } from './types';
export declare const observableArray: <T>(base: T[]) => PrimitiveSignal<T[]>;
export declare const observeArray: <T>(base: T[], update: any) => T[];
//# sourceMappingURL=array.d.ts.map

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

import * as primitive from './primitive';
// list of methods that modify the array

@@ -14,13 +13,20 @@ const methods = [

];
export const observableArray = (base) => {
// @ts-expect-error do not create a new signal if on already exists
if (base.__signal__) {
// @ts-expect-error do not create a new signal if on already exists
return base.__signal__;
export const observeArray = (base, update) => {
// @ts-expect-error idempotent
if (base.__listen__) {
// @ts-expect-error
base.__listen__(update);
return base;
}
const signal = primitive.create(base);
let listeners = [update];
const handler = {
// @ts-ignore
get(target, prop, receiver) {
if (prop === '__signal__') {
return signal;
if (prop === '__listen__') {
return (newUpdate) => {
listeners.push(newUpdate);
return () => {
listeners = listeners.filter(fn => fn !== newUpdate);
};
};
}

@@ -31,3 +37,3 @@ const reflection = Reflect.get(target, prop, receiver);

const result = reflection.apply(target, args);
signal.update(target);
listeners.forEach(fn => fn(target));
return result;

@@ -40,13 +46,7 @@ };

const result = Reflect.set(target, prop, value, receiver);
// console.log('set array ', { prop: target })
signal.update(target);
listeners.forEach(fn => fn(target));
return result;
}
};
return {
...signal,
get value() {
return new Proxy(signal.value, handler);
}
};
return new Proxy(base, handler);
};
import * as primitive from './primitive';
import { observableArray } from './array';
import { observeArray } from './array';
export function key(key) {

@@ -21,19 +21,20 @@ return (next, obj) => {

if (!signals[key]) {
const value = obj[key];
signals[key] = primitive.create(obj[key]);
let isArray = false;
if (Array.isArray(value)) {
let observableArray = [];
if (Array.isArray(obj[key])) {
isArray = true;
signals[key] = observableArray(value);
observableArray = observeArray(obj[key], signals[key].update);
}
else {
signals[key] = primitive.create(obj[key]);
}
Object.defineProperty(obj, key, {
get() {
// console.log('get object', { [key]: signals[key as string].value })
if (isArray) {
return observableArray;
}
return signals[key].value;
},
set(newValue) {
if (Array.isArray(newValue) !== isArray) {
throw new Error('Not implemented yet: Cannot change type of array');
if (Array.isArray(newValue)) {
observableArray = observeArray(newValue, signals[key].update);
}

@@ -40,0 +41,0 @@ // console.log('update object', { [key]: newValue })

{
"name": "signal-chain",
"version": "0.10.1",
"version": "0.10.2",
"author": "Christoph Franke",

@@ -5,0 +5,0 @@ "description": "Declarative Reactive Programming Library",

@@ -521,3 +521,2 @@ ![size](https://deno.bundlejs.com/badge?q=signal-chain&treeshake=[{+default+as+$+}])

- When listening to an object key, and the key had an array type, but is now being assigned a non-array, the application throws an error unsupported.
- The interface design of `$.if` makes it impossible to infer the type of the condition, making it necessary to specify the type of the condition explicitly.

@@ -532,2 +531,2 @@

- `$.await.select` operator for more intuitive promise chaining.
- Operator `$.cache` to cache the values using a key function.

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