guest-book-as icon indicating copy to clipboard operation
guest-book-as copied to clipboard

refactor: add id to each message

Open chadoh opened this issue 5 years ago • 5 comments

I recommend viewing the diff with indentation changes hidden

Clean up:

  • chmod -x files in assembly that aren't executable
  • rename PostedMessage to Message
  • make describe...it statements read more clearly

Add id:

  • create id using ulid library on the frontend
  • add new PersistentOrderedMap in the contract
    • uses a PersistentVector and a PersistentMap in tandem
    • provides limited functionality for upserting (insert or update) and other functionality that was needed by the existing app
  • only store new id field in messages, not in each individual Message
    • saves gas & storage rent costs, since ids are stored only once
    • somewhat complicates the interface, since we need to return maps instead of arrays

This lays the groundwork for doing optimistic UI updates, such as those being explored in #79

chadoh avatar May 13 '20 02:05 chadoh

gitpod-io[bot] avatar May 13 '20 02:05 gitpod-io[bot]

The failed Travis tests seem to actually be real failures this time.

mikedotexe avatar May 14 '20 15:05 mikedotexe

@mikedotexe yes, they are – we either need the ability to serialize AssemblyScript Maps to JSON objects, or we need to make getMessages return an array of arrays. Then this will actually work. I've marked as draft for now until I have time to come back and wrap this up.

chadoh avatar May 14 '20 21:05 chadoh

What is the status of this? @chadoh

AnaisUrlichs avatar Aug 24 '20 13:08 AnaisUrlichs

@AnaisUrlichs this needs to be refactored to use PersistentUnorderedMap from near-sdk-as, added in https://github.com/near/near-sdk-as/pull/85

A bigger discussion is if we want this for the Guest Book demo. Two competing goals:

  1. We want demos that are easy for newbies to understand
  2. We want demos that make a good starting point for real apps

This works toward Goal 2, somewhat at the expense of Goal 1. What do you think?

chadoh avatar Aug 25 '20 19:08 chadoh