4 changed { arg what ... moreArgs;
5 dependants.do({ arg item;
6 item.update(this, what, *moreArgs);
9 addDependant { arg dependant;
10 if (dependants.isNil, {
11 dependants = IdentitySet.new(4);
13 dependants.add(dependant);
15 removeDependant { arg dependant;
16 if (dependants.notNil, {
17 dependants.remove(dependant);
27 // responds to updates of a model
30 ^super.newCopyArgs(model).init
33 model.addDependant(this);
35 put { arg what, action;
37 actions = IdentityDictionary.new(4);
39 actions.put(what, action);
41 update { arg theChanger, what ... moreArgs;
43 action = actions.at(what);
45 action.valueArray(theChanger, what, moreArgs);
49 model.removeDependant(this);
55 (thing.asString ++ " was changed.\n").post;
64 classvar registrations;
67 *notify { arg object, message, args;
68 registrations.at(object,message).copy.do({ arg function;
69 function.valueArray(args)
74 *register { arg object,message,listener,action;
76 nr = NotificationRegistration(object,message,listener);
77 registrations.put(object,message,listener,action);
81 *unregister { arg object,message,listener;
83 lastDict = registrations.at(object,message);
85 lastDict.removeAt(listener);
86 (lastDict.size == 0).if({
87 registrations.removeAt(object,message);
88 (registrations.at(object).size == 0).if({
89 registrations.removeAt(object);
94 *registerOneShot { arg object,message,listener,action;
95 registrations.put(object,message,listener,
98 this.unregister(object,message,listener)
102 registrations = MultiLevelIdentityDictionary.new;
104 *registrationExists { |object,message,listener|
105 ^registrations.at(object,message,listener).notNil
110 //*remove { |listener|
115 NotificationRegistration {
117 var <>object,<>message,<>listener;
120 ^super.new.object_(o).message_(m).listener_(l)
123 NotificationCenter.unregister(object,message,listener)