From 895ed4f6ffe50f8b7b627eeb689bd8686ef0bc3c Mon Sep 17 00:00:00 2001 From: Daniel Stolzenberg Date: Tue, 26 Oct 2010 14:20:54 +0200 Subject: [PATCH] implemented missing replacement methods for accessor patterns in CPKeyValueObserving.j --- Foundation/CPKeyValueObserving.j | 82 ++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/Foundation/CPKeyValueObserving.j b/Foundation/CPKeyValueObserving.j index 52ae4f514..af1768944 100644 --- a/Foundation/CPKeyValueObserving.j +++ b/Foundation/CPKeyValueObserving.j @@ -813,6 +813,7 @@ var _kvoMethodForMethod = function _kvoMethodForMethod(theKey, theMethod) { return function(self, _cmd, object) { + //FIXME: do we have to call the specific willChange methods for to-many relationships? [self willChangeValueForKey:theKey]; theMethod.method_imp(self, _cmd, object); [self didChangeValueForKey:theKey]; @@ -829,6 +830,16 @@ var _kvoInsertMethodForMethod = function _kvoInsertMethodForMethod(theKey, theMe } } +var _kvoInsertManyMethodForMethod = function _kvoInsertManyMethodForMethod(theKey, theMethod) +{ + return function(self, _cmd, objects, indexes) + { + [self willChange:CPKeyValueChangeInsertion valuesAtIndexes:indexes forKey:theKey]; + theMethod.method_imp(self, _cmd, objects, indexes); + [self didChange:CPKeyValueChangeInsertion valuesAtIndexes:indexes forKey:theKey]; + } +} + var _kvoReplaceMethodForMethod = function _kvoReplaceMethodForMethod(theKey, theMethod) { return function(self, _cmd, index, object) @@ -839,6 +850,16 @@ var _kvoReplaceMethodForMethod = function _kvoReplaceMethodForMethod(theKey, the } } +var _kvoReplaceManyMethodForMethod = function _kvoReplaceManyMethodForMethod(theKey, theMethod) +{ + return function(self, _cmd, indexes, objects) + { + [self willChange:CPKeyValueChangeReplacement valuesAtIndexes:indexes forKey:theKey]; + theMethod.method_imp(self, _cmd, indexes, objects); + [self didChange:CPKeyValueChangeReplacement valuesAtIndexes:indexes forKey:theKey]; + } +} + var _kvoRemoveMethodForMethod = function _kvoRemoveMethodForMethod(theKey, theMethod) { return function(self, _cmd, index) @@ -849,4 +870,65 @@ var _kvoRemoveMethodForMethod = function _kvoRemoveMethodForMethod(theKey, theMe } } +var _kvoRemoveManyMethodForMethod = function _kvoRemoveManyMethodForMethod(theKey, theMethod) +{ + return function(self, _cmd, indexes) + { + [self willChange:CPKeyValueChangeRemoval valuesAtIndexes:indexes forKey:theKey]; + theMethod.method_imp(self, _cmd, indexes); + [self didChange:CPKeyValueChangeRemoval valuesAtIndexes:indexes forKey:theKey]; + } +} + +var _kvoUnionMethodForMethod = function _kvoUnionMethodForMethod(theKey, theMethod) +{ + return function(self, _cmd, object) + { + [self willChangeValueForKey:theKey withSetMutation:CPKeyValueUnionSetMutation usingObjects: [CPSet setWithObject: object]]; + theMethod.method_imp(self, _cmd, object); + [self didChangeValueForKey:theKey withSetMutation:CPKeyValueUnionSetMutation usingObjects: [CPSet setWithObject: object]]; + } +} + +var _kvoUnionManyMethodForMethod = function _kvoUnionManyMethodForMethod(theKey, theMethod) +{ + return function(self, _cmd, objects) + { + [self willChangeValueForKey:theKey withSetMutation:CPKeyValueUnionSetMutation usingObjects: objects]; + theMethod.method_imp(self, _cmd, objects); + [self didChangeValueForKey:theKey withSetMutation:CPKeyValueUnionSetMutation usingObjects: objects]; + } +} + +var _kvoMinusMethodForMethod = function _kvoMinusMethodForMethod(theKey, theMethod) +{ + return function(self, _cmd, object) + { + [self willChangeValueForKey:theKey withSetMutation:CPKeyValueMinusSetMutation usingObjects: [CPSet setWithObject: object]]; + theMethod.method_imp(self, _cmd, object); + [self didChangeValueForKey:theKey withSetMutation:CPKeyValueMinusSetMutation usingObjects: [CPSet setWithObject: object]]; + } +} + +var _kvoMinusManyMethodForMethod = function _kvoMinusManyMethodForMethod(theKey, theMethod) +{ + return function(self, _cmd, objects) + { + [self willChangeValueForKey:theKey withSetMutation:CPKeyValueMinusSetMutation usingObjects: objects]; + theMethod.method_imp(self, _cmd, objects); + [self didChangeValueForKey:theKey withSetMutation:CPKeyValueMinusSetMutation usingObjects: objects]; + } +} + +var _kvoIntersectManyMethodForMethod = function _kvoIntersectManyMethodForMethod(theKey, theMethod) +{ + return function(self, _cmd, objects) + { + [self willChangeValueForKey:theKey withSetMutation:CPKeyValueIntersectSetMutation usingObjects: objects]; + theMethod.method_imp(self, _cmd, objects); + [self didChangeValueForKey:theKey withSetMutation:CPKeyValueIntersectSetMutation usingObjects: objects]; + } +} + + @import "CPArray+KVO.j"