From: Marc-Aurèle DARCHE Date: Sat, 6 Feb 2016 18:57:21 +0000 (+0100) Subject: Document different techniques to share objects X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fa734d7824ae9bf1bae7fe0fad2e35fde40b1406;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git Document different techniques to share objects This has been discussed in --- diff --git a/docs/faq/electron-faq.md b/docs/faq/electron-faq.md index 643bde7..d5470f7 100644 --- a/docs/faq/electron-faq.md +++ b/docs/faq/electron-faq.md @@ -18,6 +18,40 @@ New features of Node.js are usually brought by V8 upgrades, since Electron is using the V8 shipped by Chrome browser, the shiny new JavaScript feature of a new Node.js version is usually already in Electron. +## What are the different techniques to share objects between web pages? + +To share objects between web pages (that is on the renderer side) the simplest +and more natural technique is to use a web standard API already available in all +browsers. A good candidate is the +[Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Storage), +through either the +[`window.localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) property or the +[`window.sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) property. +Note that the Storage API allows only to store strings, so objects must be +serialized as JSON. +Another candidate is +[IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API). + +Another technique, but this time specific to Electron, is to store objects in +the main process as a global variable and then to access them from the renderers +through the `remote` module: + +```javascript +// In main.js of browser process +global.sharedObject = {}; +``` + +```javascript +// js in page-1.html +require('remote').getGlobal('sharedObject').someProperty = 'some value'; +``` + +```javascript +// js in page-2.html +console.log(require('remote').getGlobal('sharedObject').someProperty); +``` + + ## My app's window/tray disappeared after a few minutes. This happens when the variable which is used to store the window/tray gets diff --git a/docs/tutorial/quick-start.md b/docs/tutorial/quick-start.md index ebf907e..ccb3836 100644 --- a/docs/tutorial/quick-start.md +++ b/docs/tutorial/quick-start.md @@ -47,6 +47,9 @@ In Electron, we have provided the [ipc](../api/ipc-renderer.md) module for communication between the main process and renderer process. There is also a [remote](../api/remote.md) module for RPC style communication. +And finally there are different techniques [to share objects between web +pages](../faq/electron-faq.md#) of the same window or of different windows. + ## Write your First Electron App Generally, an Electron app is structured like this: