Opened 8 years ago

Closed 4 years ago

#13212 closed enhancement (patchwelcome)

Add delete and forEach to dojo.Stateful

Reported by: nvd_ai61 Owned by: Kitson Kelly
Priority: low Milestone: 1.11
Component: Core Version: 1.7.0b1
Keywords: Stateful watch Cc:
Blocked By: Blocking:

Description

Dojo.Stateful is useful for implementing MVC architectures, to connect the model to the view. But, IMO, two features are missing:

1-Deletion: it should be possible to delete a property from a stateful object and be notified. Say, I have a list of products in my model and a dijit widget is showing them in the browser. When an item is deleted from the model, the widget should be notified and remove that item from the UI. At the moment, there is no API to delete a property from the stateful object. If I remove one property directly, it won't trigger the watch callback. The closest solution is to set the property to null and consider null as deleted. But it is a dirty solution as anytime I want to retrieve an item, I have to test its value against null to make sure it is not a deleted item.

2-Iteration over the properties: I assume I can iterate over dojo.Stateful object but it returns postscript, set, get, and watch functions as the properties of the object. These functions should be hidden from the iterator. A forEach function can be implemented to hide these functions.

Change History (4)

comment:1 Changed 8 years ago by bill

Component: GeneralCore
Owner: set to Kris Zyp

comment:2 Changed 6 years ago by Kitson Kelly

Milestone: tbdfuture
Owner: changed from Kris Zyp to Kitson Kelly
Status: newassigned

The first one would be possible.

The second one would be more challenging. While a forEach could be implemented, using ES5 property descriptors would be a preferred way of doing this instead of tacking on more sugar to Stateful.

Either way, they will like not be addressed in Dojo 1.X and will have to wait for Dojo 2, where we are more likely to follow the Harmony ES5 Object.observe structure.

comment:3 Changed 6 years ago by Kitson Kelly

Priority: highlow

comment:4 Changed 4 years ago by dylan

Milestone: future1.11
Resolution: patchwelcome
Status: assignedclosed

Closing as patchwelcome. A solution will exist for Dojo 2, but with Object.observe being deprecated, things will change.

Note: See TracTickets for help on using tickets.