5 this.deprecated(thisMethod, Object.class.findMethod(\new));
6 "NB Model's functionality is duplicated by Object".postln;
9 changed { arg what ... moreArgs;
10 dependants.do({ arg item;
11 item.update(this, what, *moreArgs);
14 addDependant { arg dependant;
15 if (dependants.isNil, {
16 dependants = IdentitySet.new(4);
18 dependants.add(dependant);
20 removeDependant { arg dependant;
21 if (dependants.notNil, {
22 dependants.remove(dependant);
32 // responds to updates of a model
35 ^super.newCopyArgs(model).init
38 model.addDependant(this);
40 put { arg what, action;
42 actions = IdentityDictionary.new(4);
44 actions.put(what, action);
46 update { arg theChanger, what ... moreArgs;
49 action = actions.at(what);
51 action.valueArray(theChanger, what, moreArgs);
56 model.removeDependant(this);
62 (thing.asString ++ " was changed.\n").post;
71 classvar registrations;
74 *notify { arg object, message, args;
75 registrations.at(object,message).copy.do({ arg function;
76 function.valueArray(args)
81 *register { arg object,message,listener,action;
83 nr = NotificationRegistration(object,message,listener);
84 registrations.put(object,message,listener,action);
88 *unregister { arg object,message,listener;
90 lastDict = registrations.at(object,message);
92 lastDict.removeAt(listener);
93 (lastDict.size == 0).if({
94 registrations.removeAt(object,message);
95 (registrations.at(object).size == 0).if({
96 registrations.removeAt(object);
101 *registerOneShot { arg object,message,listener,action;
103 nr = NotificationRegistration(object,message,listener);
104 registrations.put(object,message,listener,
107 this.unregister(object,message,listener)
112 registrations = MultiLevelIdentityDictionary.new;
114 *registrationExists { |object,message,listener|
115 ^registrations.at(object,message,listener).notNil
120 //*remove { |listener|
125 NotificationRegistration {
127 var <>object,<>message,<>listener;
130 ^super.new.object_(o).message_(m).listener_(l)
133 NotificationCenter.unregister(object,message,listener)