Ghirigoro
Ghirigoro
SSolidJS
Created by Ghirigoro on 4/24/2024 in #support
Mapping props to attributes
🙏
5 replies
SSolidJS
Created by Ghirigoro on 4/24/2024 in #support
Mapping props to attributes
P.S. - This is what I'm using currently:
export function createProps<
P extends Record<string, any>,
K extends keyof P,
A extends Exclude<P, K>
>(opts: { props: P; defaults?: Partial<P>; propKeys?: K[] }) {
const { props, defaults = {} as DefaultProps<P>, propKeys = [] } = opts;
const [_props, _setProps] = createSignal<P>({} as P);
const [_attrs, _setAttrs] = createSignal<A>({} as A);
createEffect(() => {
const defaultStyle: any = (defaults as any)["style"]
? (defaults as any)["style"]
: {};
const defaultClass: any = (defaults as any)["class"]
? (defaults as any)["class"]
: "";

const incomingStyle: any = props["style"] ? props["style"] : {};
const incomingClass: any = props["class"] ? props["class"] : "";

const classAttr = classes(defaultClass, incomingClass);
const styleAttr = Object.assign({}, defaultStyle, incomingStyle);

const p = mergeProps(defaults, props, {
class: classAttr,
style: styleAttr
});
const s = splitProps(p, propKeys);

_setProps(s[0] as any);
_setAttrs(s[1] as any);
});
return { props: _props, attrs: _attrs };
}
export function createProps<
P extends Record<string, any>,
K extends keyof P,
A extends Exclude<P, K>
>(opts: { props: P; defaults?: Partial<P>; propKeys?: K[] }) {
const { props, defaults = {} as DefaultProps<P>, propKeys = [] } = opts;
const [_props, _setProps] = createSignal<P>({} as P);
const [_attrs, _setAttrs] = createSignal<A>({} as A);
createEffect(() => {
const defaultStyle: any = (defaults as any)["style"]
? (defaults as any)["style"]
: {};
const defaultClass: any = (defaults as any)["class"]
? (defaults as any)["class"]
: "";

const incomingStyle: any = props["style"] ? props["style"] : {};
const incomingClass: any = props["class"] ? props["class"] : "";

const classAttr = classes(defaultClass, incomingClass);
const styleAttr = Object.assign({}, defaultStyle, incomingStyle);

const p = mergeProps(defaults, props, {
class: classAttr,
style: styleAttr
});
const s = splitProps(p, propKeys);

_setProps(s[0] as any);
_setAttrs(s[1] as any);
});
return { props: _props, attrs: _attrs };
}
5 replies
SSolidJS
Created by Ghirigoro on 3/1/2024 in #support
Hydration Mismatch. Unable to find DOM nodes for hydration key
I figured it out. The plugin's weak TS support, outdated examples, and lack of error handling made it a bit hard to figure out exactly what it wanted but I got there. Thanks all!
6 replies
SSolidJS
Created by Ghirigoro on 3/1/2024 in #support
Hydration Mismatch. Unable to find DOM nodes for hydration key
I used that plugin because it was in theory going to be easier to integrate, but it's been a grind for 2 days just to get that thing running, so I may be barking up the wrong tree. If you have any suggestions or know of any resources for integrating SolidJS into a TS/Fastify project I'm all ears. Thanks
6 replies
SSolidJS
Created by Ghirigoro on 3/1/2024 in #support
Hydration Mismatch. Unable to find DOM nodes for hydration key
Thanks for the kind offer but it's part of a monorepo and includes references to a lot of internal libraries. It would take too dig out of that monorepo and make the thing a standalone project.
6 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
Create signal from store element
Thanks! I'll take a look
18 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
Create signal from store element
OK. Thanks for the explanation. It's appreciated.
18 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
Create signal from store element
Is the idea to maintain similarity with HTML?
18 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
Create signal from store element
OK. Is there somewhere I can read up on this design. It strikes me as running counter to the tool (I'm sure it's not - I'm just inexperienced with Solid) so I'd like to understand why
18 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
Create signal from store element
Sure, but html doesn't have signals - primitives for setting and reading a value
18 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
Create signal from store element
OK. So if you have a component that is designed to both read and write to a value you shouldn't give it a signal prop? You should give it a value and a setter function?
18 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
Create signal from store element
Not sure I understand. That sounds like a change to the implementation of the input. Elsewhere I do use signals for it so I still want to keep that interface
18 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
How to react to length of store array?
Thanks for your help and sorry to waste your time
16 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
How to react to length of store array?
It's just so ingrained in me I literally don't see it any more when it's in the function parameters
16 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
How to react to length of store array?
So sorry
16 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
How to react to length of store array?
Oh crap!
16 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
How to react to length of store array?
If I add this at the top of the button component:
createEffect(() => {
console.log("index", index)
})
createEffect(() => {
console.log("index", index)
})
it always comes out 0
16 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
How to react to length of store array?
Here's the code for the button where I consitstently get an index value of 0:
const CreatePoolViewButton: Component<{ index: number }> = ({ index }) => {
return (
<button
class="flex items-center justify-center"
onClick={() => {
console.log("click", index)
// if the pool at the index is not defined, add a new pool
if (pools[index] === undefined) addPool()
else removePool(index)
}}
>
<svg
class="w-4 h-4 text-light stroke-light"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="11"></circle>
<line
style={{
transition: "transform 0.3s",
"transform-origin": "center",
transform: `rotateZ(${pools[index] !== undefined ? "90" : "0"}deg)`,
}}
x1="12"
y1="8"
x2="12"
y2="16"
></line>
<line x1="8" y1="12" x2="16" y2="12"></line>
</svg>
</button>
)
}
const CreatePoolViewButton: Component<{ index: number }> = ({ index }) => {
return (
<button
class="flex items-center justify-center"
onClick={() => {
console.log("click", index)
// if the pool at the index is not defined, add a new pool
if (pools[index] === undefined) addPool()
else removePool(index)
}}
>
<svg
class="w-4 h-4 text-light stroke-light"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="11"></circle>
<line
style={{
transition: "transform 0.3s",
"transform-origin": "center",
transform: `rotateZ(${pools[index] !== undefined ? "90" : "0"}deg)`,
}}
x1="12"
y1="8"
x2="12"
y2="16"
></line>
<line x1="8" y1="12" x2="16" y2="12"></line>
</svg>
</button>
)
}
16 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
How to react to length of store array?
No it does...
16 replies
SSolidJS
Created by Ghirigoro on 2/24/2024 in #support
How to react to length of store array?
Nope, no destructuring that I can see and:
const addPool = () => {
// setPools([...pools, { dice: 1, results: [] }])
setPools(
produce(array => {
array.push({ dice: 1, results: [] })
})
)
}
const addPool = () => {
// setPools([...pools, { dice: 1, results: [] }])
setPools(
produce(array => {
array.push({ dice: 1, results: [] })
})
)
}
has the same effect
16 replies