{"id":22203982,"url":"https://github.com/0xwal/dsyncro","last_synced_at":"2026-03-03T14:32:05.886Z","repository":{"id":37643936,"uuid":"442997188","full_name":"0xwal/dsyncro","owner":"0xwal","description":"Reactive lua table","archived":false,"fork":false,"pushed_at":"2023-01-18T03:29:51.000Z","size":33,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2024-09-20T19:02:12.896Z","etag":null,"topics":["lua"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0xwal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-30T07:13:36.000Z","updated_at":"2024-07-22T11:28:58.000Z","dependencies_parsed_at":"2023-01-19T18:33:11.472Z","dependency_job_id":null,"html_url":"https://github.com/0xwal/dsyncro","commit_stats":null,"previous_names":["0xwal/dsyncro"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xwal%2Fdsyncro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xwal%2Fdsyncro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xwal%2Fdsyncro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xwal%2Fdsyncro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xwal","download_url":"https://codeload.github.com/0xwal/dsyncro/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227769378,"owners_count":17817119,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lua"],"created_at":"2024-12-02T17:15:14.028Z","updated_at":"2026-03-03T14:32:00.864Z","avatar_url":"https://github.com/0xwal.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dsyncro\n\nA single file declarative library to extend a table and make it reactive to changes.\n\n## Motivation\n\n* I wanted a way to update values in FiveM server side and the effect should be carried out to \n  client without creating an event in both client/server to just synchronize the data.\n* I want to have the ability to encapsulate logic for accessors and mutators to transform value when setting/getting them.\n* I want the table to be smart and aware of my needs/logic.\n\n## Features\n\n* Field Watchers\n* Field Accessors\n* Field Mutators\n* Instance Global Handlers\n\n## Usage\n\n### Synchronize data to other remote/local processes\n\n#### Examples\n\n#### In this example I want to use *dsyncro* to synchronize data between server and client.\n\n```lua\nlocal player = dsyncro.new()\n\nplayer:onKeySet(function(instance, key, value)\n    -- execute your logic on all changes\n    -- send to server login\nend)\n\nfunction on_message_received(key, value) \n    -- this line to set the change received from other processes\n    player[key] = value\nend\n\n-- all changes below will trigger onKeySet callback\n\nplayer.name = 'Waleed'\n\nplayer.coords = {}\n\nplayer.coords.x = 12.6\nplayer.coords.y = 88.0\nplayer.coords.z = 98.2\n```\n\n### Execute logic on any specific value changes\n\n#### Examples\n\n##### Settings changes (String/Number)\n\n```lua\nlocal settings = dsyncro.new()\n\n-- register a change watcher to be triggered on `theme` change\nsettings['@theme'] = function(value)\n    -- do the logic to chane the UI\nend\n\n-- in later time value changed by user\nsettings.theme = 'dark'  -- will trigger the `@theme` handler\nsettings.theme = 'light' -- will trigger the `@theme` handler\n```\n\n##### User Notifications (Table as array)\n\n```lua\nlocal user = dsyncro.new()\n\n-- init\nuser.notifications = {}\nuser.name = 'Waleed'\n\n-- register a change watcher to be triggered on `theme` change\n-- **user.watch.notifications same user['@notifications']**\nuser.watch.notifications = function(notifications)\n    print(('you got %s notifications'):format(#notifications))\n    -- ...\nend\n\n\ntable.insert(user.notifications, 'You got a new friend request')\ntable.insert(user.notifications, 'Your disk space is full')\n```\n\n##### Config (Table as dictionary)\n\n```lua\nlocal user = dsyncro.new()\n\n-- init\nuser.config = { \n    channel = 'stable',\n    autoupdate = true,\n    telemetry = true\n}\n\nuser.watch.config = function(config)\n    -- dump to file\n    json.encode(config:rawItems()) -- rawItems to void dumping metadata\nend\n\n-- in later time, user changes\nuser.config.channel = 'beta'\nuser.config.autoupdate = false\nuser.config.telemetry = false\n```\n\n### Mutators\n\nWith *mutators*, you can transform value on changes\n\n#### Examples\n\n```lua\nlocal data = dsyncro.new()\n\ndata.mutator.password = function(value)\n  return fake_hash(value)\nend\n\ndata.password = '12345'\n\nprint(data.password) -- hashed\n```\n\n### Accessors\n\nWith *accessors*, you can transform value on changes\n\n#### Examples\n\n```lua\nlocal data = dsyncro.new()\n\ndata.mutator.price = function(value)\n  return value * 100\nend\n\ndata.accessor.price = function(value) \n  return value / 100\nend\n\ndata.price = '12.8'\n\nprint(data.price) -- 12.8\nprint(json.encode(data:rawItems())) -- dumping data shows price as 1280\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xwal%2Fdsyncro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xwal%2Fdsyncro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xwal%2Fdsyncro/lists"}