-
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.
Add callback invocation capabilities.
- Loading branch information
Showing
21 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
src/ActiveExpressions-Core.package/ActiveExpression.class/class/monitoring..st
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
instance creation | ||
monitoring: aBlock | ||
|
||
^ self new setMonitoredBlock: aBlock | ||
^ self basicNew | ||
setMonitoredBlock: aBlock; | ||
initialize |
4 changes: 4 additions & 0 deletions
4
src/ActiveExpressions-Core.package/ActiveExpression.class/instance/currentValue.st
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,4 @@ | ||
accessing | ||
currentValue | ||
|
||
^ monitoredBlock value |
5 changes: 5 additions & 0 deletions
5
src/ActiveExpressions-Core.package/ActiveExpression.class/instance/initialize.st
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,5 @@ | ||
initialize-release | ||
initialize | ||
|
||
super initialize. | ||
self setLastValue: self currentValue |
4 changes: 4 additions & 0 deletions
4
src/ActiveExpressions-Core.package/ActiveExpression.class/instance/invokeCallback..st
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,4 @@ | ||
callbacks | ||
invokeCallback: aBlock | ||
|
||
aBlock value |
7 changes: 7 additions & 0 deletions
7
...ssions-Core.package/ActiveExpression.class/instance/invokeCallback.lastValue.newValue..st
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,7 @@ | ||
callbacks | ||
invokeCallback: aBlock lastValue: old newValue: new | ||
|
||
aBlock argumentCount = 0 ifTrue: [^ aBlock value]. | ||
aBlock argumentCount = 1 ifTrue: [^ aBlock valueWithArguments: { new }]. | ||
aBlock argumentCount = 2 ifTrue: [^ aBlock valueWithArguments: { old . new }]. | ||
self error: 'Callback requires too many arguments' |
4 changes: 4 additions & 0 deletions
4
src/ActiveExpressions-Core.package/ActiveExpression.class/instance/lastValue.st
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,4 @@ | ||
accessing | ||
lastValue | ||
|
||
^ lastValue |
4 changes: 4 additions & 0 deletions
4
src/ActiveExpressions-Core.package/ActiveExpression.class/instance/setLastValue..st
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,4 @@ | ||
private | ||
setLastValue: anObject | ||
|
||
lastValue := anObject |
9 changes: 9 additions & 0 deletions
9
src/ActiveExpressions-Core.package/ActiveExpression.class/instance/update.st
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,9 @@ | ||
change | ||
update | ||
|
||
| newValue oldValue | | ||
oldValue := self lastValue. | ||
newValue := self currentValue. | ||
oldValue ~~ newValue ifTrue: [ | ||
self setLastValue: newValue. | ||
self callbacks do: [:each | self invokeCallback: each lastValue: oldValue newValue: newValue]] |
11 changes: 9 additions & 2 deletions
11
src/ActiveExpressions-Core.package/ActiveExpression.class/methodProperties.json
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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
{ | ||
"class" : { | ||
"monitoring:" : "sl 12/26/2017 09:55" }, | ||
"monitoring:" : "sl 12/26/2017 18:55" }, | ||
"instance" : { | ||
"callbacks" : "sl 12/26/2017 10:15", | ||
"currentValue" : "sl 12/26/2017 10:49", | ||
"initialize" : "sl 12/26/2017 10:48", | ||
"invokeCallback:" : "sl 12/26/2017 10:36", | ||
"invokeCallback:lastValue:newValue:" : "sl 12/26/2017 10:46", | ||
"lastValue" : "sl 12/26/2017 18:49", | ||
"monitoredBlock" : "sl 12/23/2017 10:14", | ||
"onChangeDo:" : "sl 12/26/2017 10:11", | ||
"printOn:" : "sl 12/26/2017 10:04", | ||
"registerCallback:" : "sl 12/26/2017 10:13", | ||
"setMonitoredBlock:" : "sl 12/26/2017 09:53" } } | ||
"setLastValue:" : "sl 12/26/2017 18:43", | ||
"setMonitoredBlock:" : "sl 12/26/2017 09:53", | ||
"update" : "sl 12/26/2017 18:49" } } |
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
7 changes: 7 additions & 0 deletions
7
src/ActiveExpressions-Tests.package/ActiveExpressionTests.class/instance/setUp.st
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,7 @@ | ||
running | ||
setUp | ||
|
||
value := 42. | ||
callbackCount := 0. | ||
activeExpression := ActiveExpression monitoring: [value]. | ||
activeExpression onChangeDo: [callbackCount := callbackCount + 1] |
6 changes: 6 additions & 0 deletions
6
...ActiveExpressionTests.class/instance/testCallbackInvocationWhenValueIdentityHasChanged.st
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,6 @@ | ||
tests - callbacks | ||
testCallbackInvocationWhenValueIdentityHasChanged | ||
|
||
value := 2. | ||
activeExpression update. | ||
self assert: 1 equals: callbackCount |
7 changes: 7 additions & 0 deletions
7
...Tests.package/ActiveExpressionTests.class/instance/testCallbackInvocationWith1Argument.st
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,7 @@ | ||
tests - callbacks | ||
testCallbackInvocationWith1Argument | ||
|
||
activeExpression onChangeDo: [:new | | ||
self assert: 1 equals: new]. | ||
value := 1. | ||
activeExpression update |
8 changes: 8 additions & 0 deletions
8
...ests.package/ActiveExpressionTests.class/instance/testCallbackInvocationWith2Arguments.st
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,8 @@ | ||
tests - callbacks | ||
testCallbackInvocationWith2Arguments | ||
|
||
activeExpression onChangeDo: [:old :new | | ||
self assert: 42 equals: old. | ||
self assert: 1 equals: new]. | ||
value := 1. | ||
activeExpression update |
6 changes: 6 additions & 0 deletions
6
...ActiveExpressionTests.class/instance/testCallbackInvocationWithMoreThan3ArgumentsFails.st
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,6 @@ | ||
tests - callbacks | ||
testCallbackInvocationWithMoreThan3ArgumentsFails | ||
|
||
activeExpression onChangeDo: [:one :two :three | 42]. | ||
value := 1. | ||
self should: [activeExpression update] raise: Error |
4 changes: 4 additions & 0 deletions
4
...sions-Tests.package/ActiveExpressionTests.class/instance/testInitializesToCurrentValue.st
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,4 @@ | ||
tests | ||
testInitializesToCurrentValue | ||
|
||
self assert: 42 equals: activeExpression lastValue |
5 changes: 5 additions & 0 deletions
5
...eExpressionTests.class/instance/testNoCallbackInvocationWhenValueIdentityHasNotChanged.st
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,5 @@ | ||
tests - callbacks | ||
testNoCallbackInvocationWhenValueIdentityHasNotChanged | ||
|
||
activeExpression update. | ||
self assert: 0 equals: callbackCount |
6 changes: 6 additions & 0 deletions
6
...veExpressions-Tests.package/ActiveExpressionTests.class/instance/testRemembersOldValue.st
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,6 @@ | ||
tests | ||
testRemembersOldValue | ||
|
||
value := 1. | ||
activeExpression update. | ||
self assert: 1 equals: activeExpression lastValue |
4 changes: 0 additions & 4 deletions
4
src/ActiveExpressions-Tests.package/ActiveExpressionTests.class/instance/testTruth.st
This file was deleted.
Oops, something went wrong.
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