rt2zz / react-native-addressbook

React Native AddressBook
82 stars 13 forks source link

Implement Update and Delete methods #1

Closed rt2zz closed 9 years ago

rt2zz commented 9 years ago

The challenge is, contacts do not have ID's. There are a few options:

  1. removeContact(index, contact, callback) which would get the contact at the specified index, verify that it is deeply equal to the supplied contact, and then if so remove the record.
  2. removeContact(index, callback) the problem is we do not know if the index has changed. We could keep the records in memory, but even then we have no gaurantee that the consumer has a fresh copy of our in memory contacts array.
  3. removeContact(config) where config = {matching: contactFragment, atIndex: index} where contactFragment is a partial set of (or whole) contact information to query against, and it will remove the contact record if all provided fields match.
  4. Do some sort of vector clock / last updated key to make sure the removeRequest is being provided against an up to date contacts array.

None of these are ideal, suggestions appreciated...

hyusetiawan commented 9 years ago

contacts do have IDs, quoting iOS developer guide: https://developer.apple.com/library/ios/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/DirectInteraction.html

The recommended way to keep a long-term reference to a particular record is to store the first and last name, or a hash of the first and last name, in addition to the identifier. When you look up a record by ID, compare the record’s name to your stored name. If they don’t match, use the stored name to find the record, and store the new ID for the record.

rt2zz commented 9 years ago

ah! fantastic. I will take a look

rt2zz commented 9 years ago

I added said recordID to the contact objects returned by getContacts

Should be fairly trivial to implement update/delete from here, although I am not sure when I will have time.

hyusetiawan commented 9 years ago

would love to get access to the recordID, right now, I am using the phone number as the ID using the module :P

On Tue, Jun 23, 2015 at 1:32 AM, Zack notifications@github.com wrote:

I added said recordID to the contact objects returned by getContacts

Should be fairly trivial to implement update/delete from here, although I am not sure when I will have time.

— Reply to this email directly or view it on GitHub https://github.com/rt2zz/react-native-addressbook/issues/1#issuecomment-114405988 .

rt2zz commented 9 years ago

checkout v1.1.4 - I added update and delete methods. warning It has not been well tested, feedback welcome.

rt2zz commented 9 years ago

Leaving this open for now, as I still need to:

  1. Test updating a record property to be null or undefined (aka deleting a property)
  2. Add error handling