halu
halu
Explore posts from servers
SSolidJS
Created by halu on 6/27/2024 in #support
SOLVED: createLazyMemo Broken?
oh is that what the v135 prevents?
11 replies
SSolidJS
Created by halu on 6/27/2024 in #support
SOLVED: createLazyMemo Broken?
tho... if the primitives solid dep gets bumped, then i'll end up with two versions again
11 replies
SSolidJS
Created by halu on 6/27/2024 in #support
SOLVED: createLazyMemo Broken?
i just started pinning my versions, hopefully that helps
11 replies
SSolidJS
Created by halu on 6/27/2024 in #support
SOLVED: createLazyMemo Broken?
much appreciated, thank you!
11 replies
SSolidJS
Created by halu on 6/20/2024 in #support
SOLVED: Non-Reactive Memo for Reactive Values?
13 replies
SSolidJS
Created by halu on 6/20/2024 in #support
SOLVED: Non-Reactive Memo for Reactive Values?
tldr - effect runs twice to dispose itself and is recreated as necessary when recalculate on demand
13 replies
SSolidJS
Created by halu on 6/20/2024 in #support
SOLVED: Non-Reactive Memo for Reactive Values?
turns out lazyMemo primitive wasn't working in my production use-case... This is what i had to do to eliminate the watcher/on() pattern: https://playground.solidjs.com/anonymous/8dc85006-f489-46b1-887a-18d1f9c7812f
function memo<T>(cb: () => any) {
/*
The goal of this memo is to minimize recalculations,
yet still supply a syncronized value on demand.
- The only way to minimize recalculation on demand in this scenario
is to track whether dependancies go dirty (recalc required).
- Avoiding recalc on reactive updates means the
subscriptions will be cleared and the effect disposed.
This actually eliminates unnecesary side-effects entirely,
but requires the effect be re-initialized each recalculation.
*/
let [last_val, set_last] = createSignal<T>();
let is_dirty = true;

let owner = getOwner();
let effect = () => {
runWithOwner(owner, () => {
createComputed(() => {
if (is_dirty) {
console.log("recalc");
// run, memo, and mark clean
set_last(cb());
is_dirty = false;
} else {
console.log("made dirty");
// Dispose effect:
// no need to listen to subsequent updates once known to be dirty
is_dirty = true;
}
});
});
};
effect();

return () => {
// if dirty, recalc on demand
// init new comp. to listen for dirty toggle
if (is_dirty) effect();
return last_val(); // return clean memo
};
}
function memo<T>(cb: () => any) {
/*
The goal of this memo is to minimize recalculations,
yet still supply a syncronized value on demand.
- The only way to minimize recalculation on demand in this scenario
is to track whether dependancies go dirty (recalc required).
- Avoiding recalc on reactive updates means the
subscriptions will be cleared and the effect disposed.
This actually eliminates unnecesary side-effects entirely,
but requires the effect be re-initialized each recalculation.
*/
let [last_val, set_last] = createSignal<T>();
let is_dirty = true;

let owner = getOwner();
let effect = () => {
runWithOwner(owner, () => {
createComputed(() => {
if (is_dirty) {
console.log("recalc");
// run, memo, and mark clean
set_last(cb());
is_dirty = false;
} else {
console.log("made dirty");
// Dispose effect:
// no need to listen to subsequent updates once known to be dirty
is_dirty = true;
}
});
});
};
effect();

return () => {
// if dirty, recalc on demand
// init new comp. to listen for dirty toggle
if (is_dirty) effect();
return last_val(); // return clean memo
};
}
(did this mostly for fun, not sure I'd actually use it)
13 replies
SSolidJS
Created by halu on 6/20/2024 in #support
SOLVED: Non-Reactive Memo for Reactive Values?
just lazyMemo was what i needed, using on/watch pattern just made it easier roll my own quickly (don't have to worry about first run tracking etc.)
13 replies
SSolidJS
Created by halu on 6/20/2024 in #support
SOLVED: Non-Reactive Memo for Reactive Values?
i misunderstood defer, doesn't really help here... found that lazyMemo doesn't really work with untrack https://playground.solidjs.com/anonymous/a7e1c35c-7687-44f7-bfa3-8530bed6a914 however, untrack is no longer be necessary given how it works (at least for my use-case) https://playground.solidjs.com/anonymous/89072d00-f796-441b-ac99-4415d22f095e https://playground.solidjs.com/anonymous/6851a2d5-d67f-42a3-894a-693c95838b1d couldn't get a track/trigger version to work as trigger is always dirty, thus the memo always computes regardless of whether signals in it callback are clean/unchanged:
function memo<T>(watch: ()=>any, cb: () => any) {
const [track, trigger] = createSignal(void 0, { equals: false })
const value = createMemo(on(track, cb, {defer:true}))
return () => {
trigger()
return value();
};
}
function memo<T>(watch: ()=>any, cb: () => any) {
const [track, trigger] = createSignal(void 0, { equals: false })
const value = createMemo(on(track, cb, {defer:true}))
return () => {
trigger()
return value();
};
}
thx for the help guys!
13 replies
SSolidJS
Created by halu on 6/20/2024 in #support
SOLVED: Non-Reactive Memo for Reactive Values?
i’ll check these out after i wake up thx guys
13 replies
SSolidJS
Created by halu on 6/20/2024 in #support
SOLVED: Non-Reactive Memo for Reactive Values?
oh cool! didn’t realize there was a deferred option in on()
13 replies
SSolidJS
Created by halu on 6/20/2024 in #support
SOLVED: Non-Reactive Memo for Reactive Values?
for better visibility, heres the function i created:
function memo<T>(watch: () => any, cb: () => T) {
let last_val: T;

let is_dirty = true;
createComputed(() => {
watch();
console.log("made dirty");
is_dirty = true;
});

return () => {
if (is_dirty) {
last_val = cb();
is_dirty = false;
}
return last_val;
};
}
function memo<T>(watch: () => any, cb: () => T) {
let last_val: T;

let is_dirty = true;
createComputed(() => {
watch();
console.log("made dirty");
is_dirty = true;
});

return () => {
if (is_dirty) {
last_val = cb();
is_dirty = false;
}
return last_val;
};
}
13 replies
SSolidJS
Created by obesecoder on 6/18/2024 in #support
DOMException *sometimes* after changing element order
4 replies
SSolidJS
Created by Blankeos on 6/18/2024 in #support
DeepTrack for a `Component[]` (Deeptrack for functions)
11 replies
SSolidJS
Created by Blankeos on 6/18/2024 in #support
DeepTrack for a `Component[]` (Deeptrack for functions)
are you trying to use a function as an object? idk why else you'd want deep reactivity on a raw function wrapped in an array it works as expected i believe? https://playground.solidjs.com/anonymous/3917c01c-1670-4e53-9341-e10ebbc79540 https://playground.solidjs.com/anonymous/ccf6e719-b81a-46fa-8255-e980be841dbb otherwise, shallow: https://playground.solidjs.com/anonymous/4a71a4ac-f5c4-4388-b057-6e0dbfc49242
11 replies
SSolidJS
Created by aryzing on 6/18/2024 in #support
Best way to pass complex values (e.g. objects) to a route?
global store, the url itself, potentially router load pattern, etc. really depends on the specifics i think
2 replies
SSolidJS
Created by halu on 5/30/2024 in #support
SOLVED: Trigger Side Effects on a Callbacks Dependency Updates
Sorry to revive, just cross-linking an update in case anyone should find themselves here in the future https://discord.com/channels/722131463138705510/1252318635989405818
181 replies
SSolidJS
Created by halu on 5/30/2024 in #support
SOLVED: Trigger Side Effects on a Callbacks Dependency Updates
^ there are million tradeoffs... look up times, mutation costs, book keeping and denormalizing data, memory footprint, data volatility, shape of data and updates (may not have control), DX, etc. really just depends on the situation and requirements what is best.
181 replies
SSolidJS
Created by halu on 5/30/2024 in #support
SOLVED: Trigger Side Effects on a Callbacks Dependency Updates
oh thats news to me
181 replies
SSolidJS
Created by halu on 5/30/2024 in #support
SOLVED: Trigger Side Effects on a Callbacks Dependency Updates
for completeness... the inversion:
{
a: {parent: ''} // no parent is the root
b: {parent: 'a'}
c: {parent: 'b'}
d: {parent: 'a'}
}
{
a: {parent: ''} // no parent is the root
b: {parent: 'a'}
c: {parent: 'b'}
d: {parent: 'a'}
}
181 replies