Confirmed users
1,340
edits
No edit summary |
|||
(8 intermediate revisions by 3 users not shown) | |||
Line 63: | Line 63: | ||
== Interface == | == Interface == | ||
typedef (DOMString or unsigned long) DataStoreKey; | |||
interface DataStore : EventTarget { | interface DataStore : EventTarget { | ||
// Returns the label of the DataSource. | // Returns the label of the DataSource. | ||
Line 75: | Line 77: | ||
// Promise<any> | // Promise<any> | ||
Promise get( | Promise get(DataStoreKey... id); | ||
// Promise<void> | // Promise<void> | ||
Promise put(any obj, | Promise put(any obj, DataStoreKey id, optional DOMString revisionId = ""); | ||
// Promise< | // Promise<DataStoreKey> | ||
Promise add(any obj, optional | Promise add(any obj, optional DataStoreKey id, optional DOMString revisionId = ""); | ||
// Promise<boolean> | // Promise<boolean> | ||
Promise remove( | Promise remove(DataStoreKey id, optional DOMString revisionId = ""); | ||
// Promise<void> | // Promise<void> | ||
Promise clear(); | Promise clear(optional DOMString revisionId = ""); | ||
readonly attribute DOMString revisionId; | readonly attribute DOMString revisionId; | ||
attribute EventHandler onchange; | |||
// Promise<unsigned long> | // Promise<unsigned long> | ||
Promise getLength(); | Promise getLength(); | ||
Line 123: | Line 124: | ||
DataStoreOperation operation; | DataStoreOperation operation; | ||
DataStoreKey id; | |||
any data; | any data; | ||
}; | |||
dictionary DataStoreChangeEventInit : EventInit { | |||
DOMString revisionId = ""; | |||
DataStoreKey id = 0; | |||
DOMString operation = ""; | |||
DOMStirng owner = ""; | |||
}; | |||
[Constructor(DOMString type, optional DataStoreChangeEventInit eventInitDict)] | |||
interface DataStoreChangeEvent : Event { | |||
readonly attribute DOMString revisionId; | |||
readonly attribute DataStoreKey id; | |||
readonly attribute DOMString operation; | |||
readonly attribute DOMString owner; | |||
}; | }; | ||
Line 134: | Line 150: | ||
datastores-owned: { | datastores-owned: { | ||
"contacts": { | "contacts": { | ||
"readonly" | "access": "readonly", | ||
"description": | "description": ... | ||
} | } | ||
}, | }, | ||
Line 146: | Line 162: | ||
datastores-access: { | datastores-access: { | ||
"contacts": { | "contacts": { | ||
" | "readonly": true, | ||
"description": | "description": "Facebook contacts", | ||
} | } | ||
}, | }, | ||
Line 200: | Line 216: | ||
=== Sync === | === Sync === | ||
The synchronization of a DataStore with a 'private' app storage can be done using the 'sync' method. Calling this method, DataStore creates a DataStoreCursor that helps the app with the synchronization starting from scratch or for a valid revisionId | The synchronization of a DataStore with a 'private' app storage can be done using the 'sync' method. Calling this method, DataStore creates a DataStoreCursor that helps the app with the synchronization starting from scratch or for a valid revisionId. The sync operation can be terminated calling cursor.close(). If something changes in the DataStore when the cursor is synchronize the app, all the changes will be managed by the cursor as additional operation: this means that when the cursor completes its tasks, the app will be always in sync with the current revisionId of the DataStore. | ||
The basic usage of the cursor is this: | The basic usage of the cursor is this: | ||
navigator.getDataStores('contacts').then(functions(stores) { | |||
if (!stores.length) return; | if (!stores.length) return; | ||
Line 213: | Line 229: | ||
switch (task.operation) { | switch (task.operation) { | ||
case 'done': | case 'done': | ||
// No additional operation has to be done | // No additional operation has to be done. | ||
dump("The current revision ID is: " + task.revisionId + "\n"); | dump("The current revision ID is: " + task.revisionId + "\n"); | ||
return; | return; | ||
Line 248: | Line 264: | ||
* Should all data stores with the same name share a schema? | * Should all data stores with the same name share a schema? | ||
* Enforcing types can be a footgun. What should a data provider do if it decides some key should have a different type? | * Enforcing types can be a footgun. What should a data provider do if it decides some key should have a different type? | ||
[[Category:Web APIs]] |