3 // responds to updates of a model
6 ^super.newCopyArgs(model).init
9 model.addDependant(this);
11 put { arg what, action;
13 actions = IdentityDictionary.new(4);
15 actions.put(what, action);
17 update { arg theChanger, what ... moreArgs;
20 action = actions.at(what);
22 action.valueArray(theChanger, what, moreArgs);
27 model.removeDependant(this);
33 (thing.asString ++ " was changed.\n").post;
42 classvar registrations;
45 *notify { arg object, message, args;
46 registrations.at(object,message).copy.do({ arg function;
47 function.valueArray(args)
52 *register { arg object,message,listener,action;
54 nr = NotificationRegistration(object,message,listener);
55 registrations.put(object,message,listener,action);
59 *unregister { arg object,message,listener;
61 lastDict = registrations.at(object,message);
63 lastDict.removeAt(listener);
64 (lastDict.size == 0).if({
65 registrations.removeAt(object,message);
66 (registrations.at(object).size == 0).if({
67 registrations.removeAt(object);
72 *registerOneShot { arg object,message,listener,action;
74 nr = NotificationRegistration(object,message,listener);
75 registrations.put(object,message,listener,
78 this.unregister(object,message,listener)
83 registrations = MultiLevelIdentityDictionary.new;
85 *registrationExists { |object,message,listener|
86 ^registrations.at(object,message,listener).notNil
91 //*remove { |listener|
96 NotificationRegistration {
98 var <>object,<>message,<>listener;
101 ^super.new.object_(o).message_(m).listener_(l)
104 NotificationCenter.unregister(object,message,listener)