Fexelitche
Fexelitche
SSolidJS
Created by Fexelitche on 11/26/2024 in #support
Mass Normalization of Props
I really would rather prefer it always being explicit.
31 replies
SSolidJS
Created by Fexelitche on 11/26/2024 in #support
Mass Normalization of Props
That seems generally problematic. Sure, the reactivity graph is very performant, and sure, you COULD react to any prop, but that doesn't mean you should. Itd actually be problematic if you couldn't choose not to - which I've experienced many a time not realizing what exactly is tracked in createEffect and such (thank you whomever made untrack). How could you possibly hope to control your updates if everything is always reactive?
31 replies
SSolidJS
Created by Fexelitche on 11/26/2024 in #support
Mass Normalization of Props
What do you mean by proxies?
31 replies
SSolidJS
Created by Fexelitche on 11/26/2024 in #support
Mass Normalization of Props
Well, that's cursed. I think Ill go make that prop normalization utility
31 replies
SSolidJS
Created by Fexelitche on 11/26/2024 in #support
Mass Normalization of Props
yes yes, of course. What exactly do you mean by defining the getters yourself? Sure, Icould wrap stuff in a lambda when providing the prop, but that'd be annoying to have to do all the time.
31 replies
SSolidJS
Created by Fexelitche on 11/26/2024 in #support
Mass Normalization of Props
But that is only with that babel-plugin is it not? (One might not have that available if one set up their project like a doofus)
31 replies
SSolidJS
Created by Fexelitche on 11/26/2024 in #support
Mass Normalization of Props
Also extensions could be made to ignore keys, include others, defaults... stuff like that
31 replies
SSolidJS
Created by Fexelitche on 11/26/2024 in #support
Mass Normalization of Props
For better detail, the implementation would go something like:
function normalizeProps(props) {
for (const key in props) {
if (typeof props[key] !== "function") {
const prev = props[key];
props[key] = () => prev;
}
}
}
function normalizeProps(props) {
for (const key in props) {
if (typeof props[key] !== "function") {
const prev = props[key];
props[key] = () => prev;
}
}
}
Typing it would be a decable tho
31 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
Nvm, its just stores, not JS. Object equivalence is lost because all values are proxied. Is there a way to retrieve the underlying value so that one can use object equivalence?
62 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
I'm at a loss. Damn.
62 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
Object equavalence fails, string version fails, weak object equivalence fails ("==")...
62 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
Yeah well I'm still trying to wrap my head around JS it seems... What is going on here even?
const index = proxy.findIndex(e => {
console.log("e", JSON.stringify(e), "element", JSON.stringify(element), " === ", e === element);
return e == element
});

Logs:
e {"id":1} element {"id":1} === false
index -1
e {"id":2} element {"id":2} === false
index -1
e {"id":1,"value":"old"} element {"id":1,"value":"old"} === false
index -1
const index = proxy.findIndex(e => {
console.log("e", JSON.stringify(e), "element", JSON.stringify(element), " === ", e === element);
return e == element
});

Logs:
e {"id":1} element {"id":1} === false
index -1
e {"id":2} element {"id":2} === false
index -1
e {"id":1,"value":"old"} element {"id":1,"value":"old"} === false
index -1
62 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
Also, with a purpose build primitive, maybe some of those less ideal cases can be remedied? Sure you can't for the generic store, but if you know you're dealing with a top-level array, you could maybe mitigate the mayhem?
62 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
Not sure I follow. Isn't that exactly what you'd want. If there is a change to some object at index i, you would want an update for that index?
62 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
As for "non-change" - it could be an in-place change, like changing a sub-field on the object. Reallocating should make sure that in-place changes still trigger updates.
62 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
A snake biting its own tail. - The proxy doesn't work, because I mutate in setStore (and wrongly so), and accessing current state of the proxy outside of setStore doesn't work, because I mutate in setStore...
62 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
Ahh. So its an ouroboros
62 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
I'd like to do that too, but the proxy doesn't seem to update synchronously, so I've been unable to retrieve the most recent state of the array. I'll try a rewrite using the proxy, but I've had nothing but issues
62 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
That's optional. You can mutate the existing or replace it. Admittedly, that fails too for object replace
62 replies
SSolidJS
Created by Fexelitche on 10/9/2024 in #support
How do one test a custom primitives?
That is not what I'm experiencing. Take the nested if statement here, currently I'm reallocating - which I shouldn't have to if reactivity extended arbitrarily, but it fails to cause an update regardless of what I do aside from reallocating everything:
const [proxy, setStore] = createStore<T[]>(initValue ?? []);

mutateByPredicate: (predicate: (element: T) => boolean, mutator: (element: T) => T | void) => {
setStore((prev) => {
for (let i = 0; i < prev.length; i++) {
if (predicate(prev[i])) {
const newElement = mutator(prev[i]);
if (newElement !== undefined && newElement !== prev[i]) {
prev[i] = newElement;
} else {
prev[i] = {...prev[i]};
}
}
}
return prev;
});
},
const [proxy, setStore] = createStore<T[]>(initValue ?? []);

mutateByPredicate: (predicate: (element: T) => boolean, mutator: (element: T) => T | void) => {
setStore((prev) => {
for (let i = 0; i < prev.length; i++) {
if (predicate(prev[i])) {
const newElement = mutator(prev[i]);
if (newElement !== undefined && newElement !== prev[i]) {
prev[i] = newElement;
} else {
prev[i] = {...prev[i]};
}
}
}
return prev;
});
},
Admittedly, writing tests for this have been... difficult, so the issue might not be the current implementation:
it('mutateByPredicate should be reactive (object replace)', () => {
return testEffect((dispose) => {
const store = createArrayStore<{ id: number }>([{ id: 0 }, { id: 1 }]);
let triggerCount = 0;

createEffect(() => {
const items = store.get();
const currentID = items[0].id;
if(currentID === 10) {
expect(triggerCount).toBe(10);
dispose();
}
const mutationCount = store.mutateByPredicate(
(el) => el.id === currentID,
(el) => ({ id: el.id + 1 })
);
expect(mutationCount).toBe(1);
triggerCount++;
});
});
});
it('mutateByPredicate should be reactive (object replace)', () => {
return testEffect((dispose) => {
const store = createArrayStore<{ id: number }>([{ id: 0 }, { id: 1 }]);
let triggerCount = 0;

createEffect(() => {
const items = store.get();
const currentID = items[0].id;
if(currentID === 10) {
expect(triggerCount).toBe(10);
dispose();
}
const mutationCount = store.mutateByPredicate(
(el) => el.id === currentID,
(el) => ({ id: el.id + 1 })
);
expect(mutationCount).toBe(1);
triggerCount++;
});
});
});
^ fail by time out
62 replies