{"id":15467268,"url":"https://github.com/jonahwilliams/signal_concept","last_synced_at":"2025-03-28T12:21:23.987Z","repository":{"id":87993117,"uuid":"91988996","full_name":"jonahwilliams/signal_concept","owner":"jonahwilliams","description":"A concept implementation of Signals for Dart.","archived":false,"fork":false,"pushed_at":"2017-05-28T07:19:12.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T12:48:02.946Z","etag":null,"topics":["async-programming","dart"],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonahwilliams.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-21T21:35:12.000Z","updated_at":"2017-05-23T20:38:52.000Z","dependencies_parsed_at":"2023-05-22T07:00:25.106Z","dependency_job_id":null,"html_url":"https://github.com/jonahwilliams/signal_concept","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonahwilliams%2Fsignal_concept","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonahwilliams%2Fsignal_concept/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonahwilliams%2Fsignal_concept/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonahwilliams%2Fsignal_concept/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonahwilliams","download_url":"https://codeload.github.com/jonahwilliams/signal_concept/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246026094,"owners_count":20711581,"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":["async-programming","dart"],"created_at":"2024-10-02T01:20:55.352Z","updated_at":"2025-03-28T12:21:22.455Z","avatar_url":"https://github.com/jonahwilliams.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# signal\n\nA proof of concept for a Signal (value + changes over time) implementation in Dart.\n\n## Usage\n\nA SignalRef allows you to change the value of a Signal.  A SignalRef can be\ncooerced into a Signal (SignalRef extends Signal).  This distinction is useful because it allows the developer to control what parts of the code can read/write a signal value and which parts can only read it.\n\n```dart\nvar ref = new SignalRef\u003cint\u003e(2);\nref.value = 3;\n\nSignal\u003cint\u003e signal = ref;\n```\n\nNew signals can be dervied from existing ones using computeN functions.  Any time the\nvalue of one of the signal changes the function will be reevaulated.\n\n```dart\nvar refOne = new SignalRef(3);\nvar refTwo = new SignalRef('Hello');\nvar sentence = computeTwo(refOne, refTwo, (a, b) =\u003e a * b);\n\nprint(sentence.value);\n// =\u003e 'HelloHelloHello';\n```\n\nAlso, here is a neat trick for computations.  Updates to computed values are defered to the\nend of the current microtask queue, allowing us to ensure a maximum of a single update per\ncomputed value.\n\n```dart\nvar refOne = new SignalRef(2);\nvar refTwo = new SignalRef(3);\nvar refThree = new SignalRef(4);\nvar refFour = new SignalRef(5);\nvar changeCount = 0;\n\nvar computed = computeFour(\n  refOne,\n  refTwo,\n  refThree,\n  refFour,\n  (a, b, c, d) =\u003e a + b + c + d,\n);\n\ncomputed.onChange((_) {\n  changeCount++;\n});\n\n// microtasks are elapsed...\n\nprint(changeCount);\n// =\u003e 1\n\nrefOne.value = 3;\nrefTwo.value = -1;\nrefThree.value = 9;\nrefFour.value = 10;\n\n// microtasks are elapsed...\n\nprint(computed.value);\n// =\u003e 21\n\nprint(changeCount);\n// =\u003e 2\n```\n\nA Signal without an initial value or a value of null is marked as \"cold\", and will\nnot trigger updates in computations.  As a result, null cannot be used as a regular value inside of signals.\n\n```dart\nvar refOne = new SignalRef();\nvar refTwo = new SignalRef(2);\n\nvar timesResult = computeTwo(refOne, refTwo, (a, b) =\u003e a * b);\nprint(timesResult.value);\n// =\u003e null\n\nrefOne.value = 3;\nprint(timesResult.value);\n// =\u003e 6\n\n```\n\nIf a signal value is set to something which is equal to the previous value, then the signal does not trigger updates.\n\n```dart\nvar calledCount = 0;\nvar refOne = new SignalRef(2);\n\nrefOne.onChange((_) {\n  calledCount++;\n});\n\nrefOne.value = 2;\nrefOne.value = 2;\n\nprint(calledCount);\n// =\u003e 0;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonahwilliams%2Fsignal_concept","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonahwilliams%2Fsignal_concept","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonahwilliams%2Fsignal_concept/lists"}