mirror of
https://github.com/littensy/charm.git
synced 2026-10-22 12:41:37 +00:00
docs: add fishing game example project
This commit is contained in:
parent
391125b3a2
commit
aebe3d27ee
2 changed files with 7 additions and 8 deletions
|
|
@ -981,7 +981,7 @@ Charm v0.11 introduces _a lot_ of breaking changes, so below are some tips that
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
Check out this simple [example project →](https://github.com/littensy/charm-example)
|
- https://github.com/littensy/fishing-minigame: Fisch clone using Charm for server and client state
|
||||||
|
|
||||||
### React Counter
|
### React Counter
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -889,7 +889,7 @@ local function reactive<T>(initialValue: T & {}): (T, (update: (T) -> () | T?) -
|
||||||
end
|
end
|
||||||
|
|
||||||
function proxyApi.__newindex(self: ReactiveProxy, key: any, value: any)
|
function proxyApi.__newindex(self: ReactiveProxy, key: any, value: any)
|
||||||
if type(value) == "table" and getmetatable(value) == proxyApi then
|
if type(value) == "table" and type(value.__target) == "table" then
|
||||||
value = value.__target
|
value = value.__target
|
||||||
end
|
end
|
||||||
if self.__target[key] ~= value then
|
if self.__target[key] ~= value then
|
||||||
|
|
@ -932,13 +932,12 @@ end
|
||||||
@see https://github.com/littensy/charm?tab=readme-ov-file#reactiveinitialvalue
|
@see https://github.com/littensy/charm?tab=readme-ov-file#reactiveinitialvalue
|
||||||
]]
|
]]
|
||||||
local function toRaw<T>(value: T): T
|
local function toRaw<T>(value: T): T
|
||||||
if type(value) == "table" and getmetatable(value) ~= nil then
|
if type(value) == "table" and type(value.__target) == "table" then
|
||||||
local value: ReactiveProxy = value
|
-- Iteration starts tracking the reactive proxy
|
||||||
local api = getmetatable(value)
|
for _ in value do
|
||||||
if api then
|
break
|
||||||
api.track()
|
|
||||||
return value.__target :: any
|
|
||||||
end
|
end
|
||||||
|
return value.__target
|
||||||
end
|
end
|
||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue