1 # WARNING: This is a developer preview of our new code, not everything works yet, but new apps should use it nonetheless
2 # Old apps should check out branch v0.6.9 instead, which has actual syncing to actual remote storage working.
4 # Adding remoteStorage.js v0.7 to your app:
5 #### add "remoteStorage.js" (you can copy it from this repo)
6 #### in index.html, include this script and any modules you plan to load:
8 <script src="remoteStorage.js"></script>
9 <script src="tasks-0.1.js"></script>
11 #### in the place where you want the remoteStorage element to go, add a div:
13 <div id="remotestorage-connect"></div>
15 #### then in your app's onload function, add a call to put the 'connect your remote storage' UI into that div,
17 remoteStorage.displayWidget('remotestorage-connect');
19 #### load the 'tasks' module,
21 remoteStorage.loadModule('tasks', '0.1', 'rw');
23 #### open a private tasks list called 'todos':
25 todos = remoteStorage.tasks.getPrivateList('todos');
27 #### and specify your handlers for 'error' and 'change' on the task list:
29 todos.on('error', function(err) {
31 todos.on('change', function(id, obj) {
35 #### note that your change handler will be called with an object that has an 'origin' field, that comes with a value of 'tab', 'device', or 'cloud'
37 Note: maybe 'window' is a better term than 'tab' here, this sort of details is still subject to change in the final v0.7
40 # using the tasks list:
42 #### function list.getIds();
44 returns an array of id's, which you can use to retrieve the actual objects.
46 #### function list.get(id);
48 returns an object from the list, or undefined if there is no object in the list with that id
50 #### function list.set(id, obj);
52 sets the item with that id to that object (might trigger a 'change' event with origin 'tab').
54 #### function list.add(text);
56 creates a new todo item with that text, completed set to false, and a randomly generated id, which is returned by the function.
58 #### function list.remove(id);
62 #### function list.markAsCompleted(id);
64 marks that todo item as completed (you can see we really have a higher-level API here that understands that tasks are things that have a boolean 'completed' field)
66 #### function list.isCompleted(id);
68 returns true or false. this one is maybe a bit silly, you could also just get the object and read the obj.completed field. or maybe we should make obj.isCompleted(),
69 inline with OO practice. Anyway, you get the idea. I hope that with this everybody can write apps very easily based on modules like this. For now i only included 'tasks', but once this works it should be easy to make first versions of other modules like 'documents', 'contacts', 'photos', 'stuff', 'music', etcetera. Pull requests welcome! :)