-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change was mostly inspired by this issue, dphfox/Fusion#310 I totally agree with Observers being *completely* redundant, and for the most part unneeded, because most the time when you're creating an Observer it's just to pipe it straight into a `:onBind()` or `:onChange()` call. I've replaced Observers with a function simply called `observe()` which takes the target and the callback as arguments and returns a disconnect function. It adds a set inside the target that holds all of the callbacks and when that target value is evaluate it calls all of those observe tasks, essentially removing the Observer "middleman". (I know I'm not good at describing these things, you can just look at the changes yourself to see what I mean)
- Loading branch information
1 parent
d629166
commit 68370aa
Showing
17 changed files
with
82 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
local package = script.Parent.Parent | ||
|
||
local Symbols = require(package.Symbols) | ||
local Types = require(package.Types) | ||
|
||
local castToState = require(package.State.castToState) | ||
|
||
local function observe<V>(target: Types.UsedAs<V>, callback: (V) -> ()) | ||
if not castToState(target) then | ||
return | ||
end | ||
|
||
local observers = target[Symbols.Observers] | ||
|
||
if observers == nil then | ||
observers = {} | ||
|
||
target[Symbols.Observers] = observers | ||
end | ||
|
||
observers[callback] = true | ||
|
||
return function() | ||
observers[callback] = nil | ||
end | ||
end | ||
|
||
return observe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.