Skip to content

observable collection item removal #9

Description

@jayvdb

It seems the event for item removal doesnt include the removed item.

from pydispatch import Dispatcher
from pydispatch.properties import DictProperty

#old_dict = sys.modules
old_dict = {}

class MyDictListener(object):
    def on_new_data(self, emitter, dict_, **kwargs):
        new_keys = kwargs.get('keys')
        if new_keys:
            for key in new_keys:
                print('new item: {}={}'.format(key, dict_[key]))
        else:
            print('unknown', kwargs)

class MyDictWrapper(Dispatcher):
    new_dict = DictProperty(old_dict)

listener = MyDictListener()
dict_wrapper = MyDictWrapper()
dict_wrapper.bind(new_dict=listener.on_new_data)

new_dict = dict_wrapper.new_dict

new_dict['a'] = 1
del new_dict['a']
new item: a=1
unknown {'old': None, 'property': <<class 'pydispatch.properties.DictProperty'>: new_dict>}

I saw I can have old populated, and then I could do a diff in the listener, but that seems wasteful as the underlying collection knows which item is being removed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions