Hildebrandt Tobias
08/14/2023, 10:05 AMRobert Jaros
08/14/2023, 10:09 AMHildebrandt Tobias
08/14/2023, 10:12 AMEdoardo Luppi
08/14/2023, 10:12 AMHildebrandt Tobias
08/14/2023, 10:14 AMunknown TopLevelEntity
Edoardo Luppi
08/14/2023, 10:16 AMHildebrandt Tobias
08/14/2023, 10:19 AMAdam S
08/14/2023, 10:20 AMcreate()
function. Have you written anything for that so far? Can you share it here?Edoardo Luppi
08/14/2023, 10:21 AMHildebrandt Tobias
08/14/2023, 10:25 AM[]
type and then wandered off to Dukat. My first assumption was that it's the kotlin equivalent to Array
, but I'd have to look that up to be sure.Adam S
08/14/2023, 10:26 AMHildebrandt Tobias
08/14/2023, 10:26 AMAdam S
08/14/2023, 10:27 AMdynamic
, so if you ever see a type that's confusing, just use dynamic
and try and come back to it later. Maybe it can be represented with an external type, but maybe it needs something more complicated,Edoardo Luppi
08/14/2023, 10:28 AMAny
instead of dynamic
seems to be the general consensus for wrappers.Hildebrandt Tobias
08/14/2023, 10:28 AMEdoardo Luppi
08/14/2023, 10:29 AMAdam S
08/14/2023, 10:29 AMHildebrandt Tobias
08/14/2023, 10:29 AM@JsModule
annonations and such?Adam S
08/14/2023, 10:30 AMHildebrandt Tobias
08/14/2023, 10:31 AMAdam S
08/14/2023, 10:31 AMHildebrandt Tobias
08/14/2023, 12:13 PMexternal fun create(createState: dynamic): dynamic
and used it like so:
val useTestStore = create({
var test = "test"
})
So far so good, no errors, but the variable declaration is probably wrong.
Trying to get the value again I used:
val test = useTestStore {
it.asDynamic().test
}
println("test: $test")
When I run it I get test: undefined
So since I want to use Interfaces eventually anyway I figured I need to at least Wrap the StateCreator
and pass a type. But that's where I can't figure out how to go on.Hildebrandt Tobias
08/14/2023, 12:15 PMexport type StateCreator<
T,
Mis extends [StoreMutatorIdentifier, unknown][] = [],
Mos extends [StoreMutatorIdentifier, unknown][] = [],
U = T,
> = ((
setState: Get<Mutate<StoreApi<T>, Mis>, 'setState', never>,
getState: Get<Mutate<StoreApi<T>, Mis>, 'getState', never>,
store: Mutate<StoreApi<T>, Mis>
) => U) & { $$storeMutators?: Mos }
I assume this is the way?
external fun <T>create(createState: dynamic): dynamic
external class StateCreator<T, Mis, Mos> {
fun setState(): dynamic
fun getState(): dynamic
fun store(): dynamic
}
Hildebrandt Tobias
08/14/2023, 12:18 PMinterface testInterface {
var test: String
}
val useTestStore = create<testInterface>({
test = "test" // var test unknown
})
Adam S
08/14/2023, 12:22 PMexternal interface
, not an external class
Hildebrandt Tobias
08/14/2023, 12:25 PMAdam S
08/14/2023, 12:26 PMHildebrandt Tobias
08/14/2023, 12:26 PMundefined
when trying to get the state thoughAdam S
08/14/2023, 12:30 PMsetState: Get<Mutate<StoreApi<T>, Mis>, 'setState', never>,
getState: Get<Mutate<StoreApi<T>, Mis>, 'getState', never>,
store: Mutate<StoreApi<T>, Mis>
should be mapped to Kotlin vals, or most likely varsAdam S
08/14/2023, 12:32 PMAdam S
08/14/2023, 12:50 PMcreate
isn't mapped to a function, it's mapped to a val 🤯
export const create = (<T>(createState: StateCreator<T, [], []> | undefined) =>
createState ? createImpl(createState) : createImpl) as Create
and the type, Create
, has a function that you invokeEdoardo Luppi
08/14/2023, 12:50 PMGet<Mutate<StoreApi<T>, Mis>, 'setState', never>
The beautiful TS type system lmao
But this would get translated to
Get<Mutate<StoreApi<T>, Mis>, String, Nothing>
Edoardo Luppi
08/14/2023, 12:51 PMEdoardo Luppi
08/14/2023, 12:52 PMasDynamic
sometimes.Hildebrandt Tobias
08/14/2023, 1:45 PMHildebrandt Tobias
08/14/2023, 1:48 PMEdoardo Luppi
08/14/2023, 2:47 PMHildebrandt Tobias
08/14/2023, 4:22 PMexport const create = (<T>(createState: StateCreator<T, [], []> | undefined) => createState ? createImpl(createState) : createImpl) as Create
is a function reference inside a val.
The StateCreator is type
which is a typealias
but the type is a function that sets three values setState, getState and store and returns as the generic T?
``````Hildebrandt Tobias
08/14/2023, 4:37 PMexternal fun <T>create(block: (StateCreator<T, Nothing, Nothing>) -> T): dynamic
Edoardo Luppi
08/14/2023, 4:38 PMHildebrandt Tobias
08/14/2023, 4:55 PM