{"id":16086994,"url":"https://github.com/guillep/observableslots","last_synced_at":"2025-07-24T14:33:29.922Z","repository":{"id":147866019,"uuid":"170130528","full_name":"guillep/ObservableSlots","owner":"guillep","description":"Pharo language extension to have slots that announce changes","archived":false,"fork":false,"pushed_at":"2019-02-15T18:02:49.000Z","size":15,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T14:43:57.708Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Smalltalk","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guillep.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-02-11T13:10:06.000Z","updated_at":"2021-06-02T20:56:23.000Z","dependencies_parsed_at":"2023-05-27T18:00:19.629Z","dependency_job_id":null,"html_url":"https://github.com/guillep/ObservableSlots","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/guillep/ObservableSlots","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guillep%2FObservableSlots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guillep%2FObservableSlots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guillep%2FObservableSlots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guillep%2FObservableSlots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guillep","download_url":"https://codeload.github.com/guillep/ObservableSlots/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guillep%2FObservableSlots/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266855929,"owners_count":23995585,"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","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-09T13:26:44.829Z","updated_at":"2025-07-24T14:33:29.483Z","avatar_url":"https://github.com/guillep.png","language":"Smalltalk","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ObservableSlots\n\nPharo language extension to have slots that announce changes\n\n# Installation\n\nExecute the following lines in a playground:\n\n```smalltalk\nMetacello new\n    baseline: 'ObservableSlot';\n    repository: 'github://guillep/ObservableSlots/src';\n    load.\n```\n\n# Usage\n\n## Defining Observable Slots\n\nOnce the package is loaded, you will be able to create new classes with observable slots like this:\n\n```smalltalk\nObject subclass: #ObservablePoint\n\tslots: { #x =\u003e ObservableSlot. \n\t\t\t\t#y }\n\tclassVariables: {  }\n\tpackage: 'ObservableSlot'\n```\n\nAn observable slot works like a normal slot, and hides completely the announcement mechanism that is behind:\n\n```smalltalk\n\"Create Accessors\"\nObservablePoint \u003e\u003e x: aNumber [\n  x := aNumber\n].\nObservablePoint \u003e\u003e x [\n  ^ x\n].\n\n\"Create an observable point and use it normally\"\npoint := ObservablePoint new.\npoint x: 17.\nself assert: point x equals: 17.\n```\n\n## Subscribing to Slots Changes\n\nTo subscribe to the ObservableSlot changes, your object can use the `TObservable` trait, that contains some methods for subscription and explicit notification.\n\n```smalltalk\nObject subclass: #ObservablePoint\n  uses: TObservable\n\tslots: { #x =\u003e ObservableSlot. \n\t\t\t\t#y }\n\tclassVariables: {  }\n\tpackage: 'ObservableSlot'\n```\n\nThen we can subscribe to it doing\n\n```smalltalk\n\"Create an observable point and use it normally\"\npoint property: #x whenChangedDo: [ \"your code\" ].\n```\n\nThe method `property:whenChangedDo:` receives as first argument the name of the instance variable (as a symbol) and as second argument a block.\nThe block has either a single parameter (where it will be passed the value that has just changed) or no parameter at all.\n\n## Manually Announce Slots Changes\n\nSometimes we want to have control on the announcements and manually announce that a value changed.\nFor example, imagine a (not so) more complex graph like:\n\n```\nabObservablePoint -- x (observable) --\u003e someObject -- someOtherInstVar (non-observable) --\u003e someOtherObject\n```\n\nIf `someObject` has its `someOtherInstVar` changed, we could want to announce that `x` changed too.\nThat could be done by doing:\n\n```smalltalk\npoint notifyPropertyChanged: #x.\n```\n\n## Exceptions\n\nIf the property we want to subscribe or notify to does not exist a `SlotNotFound` will be risen.\nIf the property exists but is not observable a `NonObservableSlotError` will be risen.\n\n\n# Implementation Details\n\nThis implementation uses a `ValueHolder` to capture changes, and Slots to intercept reading and writing.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguillep%2Fobservableslots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguillep%2Fobservableslots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguillep%2Fobservableslots/lists"}