MeoMix / SongBuzz

A Google Chrome extension which allows users to create, maintain, and interact with playlists streamed from YouTube.
23 stars 4 forks source link

Need to rethink how I'm writing objects to local storage #37

Closed MeoMix closed 12 years ago

MeoMix commented 12 years ago

I'm currently trying to finish implementing renaming playlists.

I've ran into a bit of a snag in my logic, though, and I wanted to write it down just in case anyone had any brilliant ideas.

So, I've got two objects which have the ability to save themselves to local storage: Playlists and Playlist.

Playlists writes a serialized array of Playlist objects, recording their state for loading later. Playlist, on the other hand, saves an array of Song.

This seemed all well and good at the start -- a Playlist cares about loading up the songs inside of itself, and then Playlists handles the rest.

Now, though, I see a flaw in the logic. I would like to rename a single Playlist. Yet, if I change the Playlist name and call save -- the name is not saved (its songs are). I need to call Playlists' save method whenever I want to make a change to a singular playlist. That seems poor -- Playlist objects should be responsible for saving themselves.

MeoMix commented 12 years ago

I fixed all of this while on my plane trip back home! Now, Playlists just maintains an associative array of playlist ID's and their related Playlist objects. Each Playlist object writes itself to local storage (key is its ID). Songs are stored as part of the object serialized.