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

@solid-primitives/memo

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solid-primitives/memo - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

dist/chunk-R4XF5HQ4.js

1

dist/index.d.ts

@@ -14,2 +14,3 @@ import { Accessor, Setter } from 'solid-js';

* @param options set computation name for debugging pourposes
* - `options.initial` — an array of functions to be run initially and tracked. *(useful for runing code before other pure computations)*
* @returns track() function

@@ -16,0 +17,0 @@ *

141

dist/index.js

@@ -1,134 +0,11 @@

// src/index.ts
import {
createSignal,
createComputed,
untrack,
getOwner,
onCleanup,
createMemo,
runWithOwner,
on,
getListener,
createRoot
} from "solid-js";
import { debounce, throttle } from "@solid-primitives/scheduled";
var set = (setter) => (v) => {
setter(() => v);
};
var callbackWith = (fn, v) => fn.length > 0 ? () => fn(untrack(v)) : fn;
function createPureReaction(onInvalidate, options) {
const [trackedList, setTrackedList] = createSignal([]);
let addedTracked = false;
createComputed(() => {
if (!trackedList().length)
return;
if (addedTracked) {
addedTracked = false;
trackedList().forEach((tracking) => tracking());
} else {
setTrackedList([]);
untrack(onInvalidate);
}
}, options);
return (tracking) => {
addedTracked = true;
setTrackedList((p) => [...p, tracking]);
};
}
function createCurtain(sources, value, options = {}) {
const [last, setLast] = createSignal(value, options);
for (const fn of sources)
createComputed(on(fn, set(setLast), { defer: true }));
return last;
}
function createWritableMemo(fn, value, options) {
const [signal, setSignal] = createSignal(fn(value), options);
const calc = callbackWith(fn, signal);
createComputed(on(calc, set(setSignal), { defer: true }));
return [signal, setSignal];
}
function createDebouncedMemo(calc, timeoutMs, options = {}) {
const [state, setState] = createSignal(options.value, options);
const fn = debounce(() => track(() => setState(calc)), timeoutMs);
const track = createPureReaction(() => {
fn();
track(() => calc(state()));
}, options);
track(() => setState(calc));
return state;
}
function createThrottledMemo(calc, timeoutMs, options = {}) {
const [state, setState] = createSignal(options.value, options);
const fn = throttle(() => track(() => setState(calc)), timeoutMs);
const track = createPureReaction(fn, options);
track(() => setState(calc));
return state;
}
function createAsyncMemo(calc, options = {}) {
const [state, setState] = createSignal(options.value, options);
const order = [];
createComputed(async () => {
const value = calc(untrack(state));
if (value instanceof Promise) {
order.push(value);
value.then((r) => order.includes(value) && setState(() => r));
value.finally(() => {
const index = order.indexOf(value);
order.splice(0, index + 1);
});
} else
setState(() => value);
}, void 0, options);
return state;
}
function createLazyMemo(calc, value, options) {
var _a;
const owner = (_a = getOwner()) != null ? _a : void 0;
let listeners = 0;
let lastest = value;
let dirty = true;
let memo;
let dispose;
onCleanup(() => dispose == null ? void 0 : dispose());
const track = createPureReaction(() => dirty = !memo);
return () => {
if (!getListener()) {
if (memo)
return memo();
if (dirty)
track(() => lastest = calc(lastest));
dirty = false;
return lastest;
}
listeners++;
onCleanup(() => listeners--);
if (!memo) {
createRoot((_dispose) => {
dispose = _dispose;
memo = createMemo(() => {
if (listeners)
return lastest = calc(lastest);
dispose();
dispose = memo = void 0;
return lastest;
}, lastest, options);
}, owner);
}
return memo();
};
}
function createMemoCache(...args) {
const cache = /* @__PURE__ */ new Map();
const owner = getOwner();
const key = typeof args[1] === "function" ? args[0] : void 0, calc = typeof args[1] === "function" ? args[1] : args[0], options = typeof args[1] === "object" ? args[1] : typeof args[2] === "object" ? args[2] : {};
const run = (key2) => {
if (cache.has(key2))
return cache.get(key2)();
const memo = runWithOwner(owner, () => createLazyMemo((prev) => calc(key2, prev), void 0, options));
if (options.size === void 0 || cache.size < options.size)
cache.set(key2, memo);
return memo();
};
return key ? () => run(key()) : run;
}
createAsyncMemo,
createCurtain,
createDebouncedMemo,
createLazyMemo,
createMemoCache,
createPureReaction,
createThrottledMemo,
createWritableMemo
} from "./chunk-R4XF5HQ4.js";
export {

@@ -135,0 +12,0 @@ createAsyncMemo,

{
"name": "@solid-primitives/memo",
"version": "0.2.2",
"version": "0.3.0",
"description": "Collection of custom memo primitives. They extend Solid's createMemo functionality while keeping the usage similar.",

@@ -34,5 +34,13 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",

"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"main": "./dist/server.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"node": {
"import": "./dist/server.js",
"require": "./dist/server.cjs"
},
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"files": [

@@ -39,0 +47,0 @@ "dist"

@@ -338,2 +338,8 @@ <p>

0.3.0
Improve how `createPureReaction`, `createThrottledMemo` and `createDebouncedMemo` work when created during batched effect.
Provida a separate tuntime for server.
</details>

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