From e43ac7aeb1fef5c1781b6e38c2a3a8b0fa280c7e Mon Sep 17 00:00:00 2001 From: Daniel Brain Date: Tue, 7 Mar 2017 23:38:40 -0800 Subject: [PATCH] Add comments for first example --- README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 35800ab5..5197b940 100644 --- a/README.md +++ b/README.md @@ -15,26 +15,41 @@ Send a message to another window, and: ## Simple listener and sender with error handling ```javascript +// Set up a listener + postRobot.on('getUser', function(event) { + + // Have it return some data to the calling window + return { - id: event.data.id, + id: 1234, name: 'Zippy the Pinhead', + + // Yep, we're even returning a function to the other window! + logout() { - currentUser.logout(); + return $currentUser.logout(); } }; }); ``` ```javascript +// Call the listener, on a different window, on a different domain + postRobot.send(someWindow, 'getUser', { id: 1337 }).then(function(event) { var user = event.data; console.log(event.source, event.origin, 'Got user:', user); + // Call the user.logout function from the other window! + user.logout(); }).catch(function(err) { + + // Handle any errors that stopped our call from going through + console.error(err); }); ```