W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2010

Re: localStorage Event

From: Jonas Sicking <jonas@sicking.cc>
Date: Thu, 28 Jan 2010 15:52:35 -0800
Message-ID: <63df84f1001281552o38e5d07fp8e4e1d5c14209a01@mail.gmail.com>
To: Olli@pettay.fi
Cc: Jared Morse <jarcoal@gmail.com>, public-webapps@w3.org
On Thu, Jan 28, 2010 at 3:38 PM, Olli Pettay <Olli.Pettay@helsinki.fi> wrote:
> On 1/29/10 12:22 AM, Jared Morse wrote:
>>
>> Perhaps I am mistaken, but I believe you would still have to go around
>> and add that trigger to all the places the value is changed from.
>
> Well you could do something like
> Storage.prototype.setItemAndNotify =
>  function (key, data) {
>    this.setItem(key, data);
>    var e = document.createEvent("StorageEvent");
>    e.initStorageEvent(...);
>    window.dispatchEvent(e);
>  }
>
> and use that when you set some item.
> Or just replace setItem method using prototype.
>
> That way you get the behavior you want, but still allow the
> other behavior.

I don't think replacing setItem on the protochain will work for code that does:

localStore.bar = "baz";

(I guess chalk this up as another reason why catchalls are bad).

/ Jonas
Received on Thursday, 28 January 2010 23:53:28 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:36 GMT