Zanoryt
Zanoryt
Explore posts from servers
SSolidJS
Created by Zanoryt on 8/12/2023 in #support
Now using createResource(), the content never loads.
I'll give that a shot 🙂
11 replies
SSolidJS
Created by Zanoryt on 8/12/2023 in #support
Now using createResource(), the content never loads.
reports.loading would never be false
11 replies
SSolidJS
Created by Zanoryt on 8/12/2023 in #support
Now using createResource(), the content never loads.
Yeah I did that too, and it didn't work.
11 replies
SSolidJS
Created by Zanoryt on 8/12/2023 in #support
Now using createResource(), the content never loads.
I am able to use createStore+createEffect, but wanted to use createResource.
11 replies
SSolidJS
Created by Zanoryt on 8/12/2023 in #support
Now using createResource(), the content never loads.
Do I need to trigger it to load any other way?
11 replies
SSolidJS
Created by Trader101 on 7/28/2023 in #support
pass session via `<Outlet />`
This is where you would consider createEffect() to watch for changes to the session, update the related store in the context, and anything underneath (in the tree) will benefit from any changes to the store.
5 replies
SSolidJS
Created by Trader101 on 7/28/2023 in #support
pass session via `<Outlet />`
Have you thought about putting the session inside a Context? Then you can access that context (assuming you wrap the Context Provider in the main app outside of the Outlet area) from anything.
5 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
This has really extracted out some functionality nicely. I'm impressed.
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
import { createContext, createEffect, on, useContext } from "solid-js";
import { createStore } from "solid-js/store";
import { useWebsocket } from "./Websocket";

export const makeDataStreamContext = () => {
let intialized = false;
const [state, setState] = createStore({
favoriteStationIds: [15150280, 705556],
stationsToMonitor: [] as number[],
stations: [] as any[],
stationData: {} as any,
});

const [websocketState, _websocket]: any = useWebsocket();
createEffect(on(() => websocketState.socket, (socket: any) => {
if (intialized) return;

if (socket) {
intialized = true;
socket.on("station:monitor:data", (data: any) => {
console.log("DS: station:monitor:data", data);
});
socket.on("station:monitor:started", (data: any) => {
console.log("DS: station:monitor:started", data);
if (state.stations.filter((station) => station.id === data.station.id).length === 0) {
setState("stations", [...state.stations, { id: data.station.id, ident: data.station.ident, monitoring: true, messages: [] }]);
// if (stationIdSelected == data.stationId) setStore("stationSelected", data.station);
console.log(`DS: Browser ${data.browserId}: Started monitoring station ${data.station.id}`)
}
});
}
}));

return [state, {
addStationToMonitor: (stationId: number) => {
setState('stationsToMonitor', [...state.stationsToMonitor, stationId]);
websocketState.socket.emit("station:monitor:start", stationId);
},
removeStationToMonitor: (stationId: number) => {
setState('stationsToMonitor', state.stationsToMonitor.filter((id: number) => id !== stationId));
websocketState.socket.emit("station:monitor:stop", stationId);
}
}] as const;
}
export type DataStreamContextType = ReturnType<typeof makeDataStreamContext>;
export const DataStreamContext = createContext<DataStreamContextType>();

export const DataStreamProvider = (props: any) => {
const dataStream = makeDataStreamContext();

return (
<DataStreamContext.Provider value={dataStream}>
{props.children}
</DataStreamContext.Provider>
);
}

export const useDataStream = () => { return useContext(DataStreamContext); }
import { createContext, createEffect, on, useContext } from "solid-js";
import { createStore } from "solid-js/store";
import { useWebsocket } from "./Websocket";

export const makeDataStreamContext = () => {
let intialized = false;
const [state, setState] = createStore({
favoriteStationIds: [15150280, 705556],
stationsToMonitor: [] as number[],
stations: [] as any[],
stationData: {} as any,
});

const [websocketState, _websocket]: any = useWebsocket();
createEffect(on(() => websocketState.socket, (socket: any) => {
if (intialized) return;

if (socket) {
intialized = true;
socket.on("station:monitor:data", (data: any) => {
console.log("DS: station:monitor:data", data);
});
socket.on("station:monitor:started", (data: any) => {
console.log("DS: station:monitor:started", data);
if (state.stations.filter((station) => station.id === data.station.id).length === 0) {
setState("stations", [...state.stations, { id: data.station.id, ident: data.station.ident, monitoring: true, messages: [] }]);
// if (stationIdSelected == data.stationId) setStore("stationSelected", data.station);
console.log(`DS: Browser ${data.browserId}: Started monitoring station ${data.station.id}`)
}
});
}
}));

return [state, {
addStationToMonitor: (stationId: number) => {
setState('stationsToMonitor', [...state.stationsToMonitor, stationId]);
websocketState.socket.emit("station:monitor:start", stationId);
},
removeStationToMonitor: (stationId: number) => {
setState('stationsToMonitor', state.stationsToMonitor.filter((id: number) => id !== stationId));
websocketState.socket.emit("station:monitor:stop", stationId);
}
}] as const;
}
export type DataStreamContextType = ReturnType<typeof makeDataStreamContext>;
export const DataStreamContext = createContext<DataStreamContextType>();

export const DataStreamProvider = (props: any) => {
const dataStream = makeDataStreamContext();

return (
<DataStreamContext.Provider value={dataStream}>
{props.children}
</DataStreamContext.Provider>
);
}

export const useDataStream = () => { return useContext(DataStreamContext); }
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
It works! Incredible.
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
let me give it a shot
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
elegant
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
oooooooh
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
Trying to call socket.on() from inside of the DataStreamContext, but of course at time of initialization the socket does not yet exist. Is there some way to do this so that it can register those once the socket exists?
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
One more issue.
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
Fantastic, that worked
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
right, the second item is the functions
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
ohh
38 replies
SSolidJS
Created by Zanoryt on 7/22/2023 in #support
How can I access a store from the parent context from inside of a nested context?
i have it in websocket (second item)
38 replies