Skip to content

Commit

Permalink
Misc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jakiestfu committed Aug 1, 2016
1 parent c9e675e commit 482de29
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 23 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="http://dollarshaveclub.github.io/postmate/pages/">
<img src="http://i.imgur.com/qOIF7XH.png">
</a>
> A simple, promise-based `postMessage` library
> A powerful, simple, promise-based `postMessage` library.
* [Installing](#installing)
* [Glossary](#glossary)
Expand All @@ -21,8 +21,8 @@ $ bower i postmate # Install via Bower
* **`Consumer`**: The API that the `Client` or `Host` exposes

## Usage
The `Client` begins communication with the host. A handshake is sent, the `Host` responds with
a handshake reply, and the two are bound and ready to mingle.
The `Client` begins communication with the `Host`. A handshake is sent, the `Host` responds with
a handshake reply, finishing `Client` initialization. The two are bound and ready to mingle.

***

Expand Down Expand Up @@ -70,4 +70,5 @@ Client Page Ready

## API


## Licensing
3 changes: 0 additions & 3 deletions client.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
url
})
.then(host => {
// host.get('token', {
// oauthToken: 'foo-bar-baz'
// }).then(ccToken => console.log(ccToken));
console.log("Client Page Ready");
host.get('height', {foo:'bar'})
.then(height => host.frame.style.height = `${height}px`);
Expand Down
2 changes: 1 addition & 1 deletion host.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<script type="text/javascript" src="./build/postmate.min.js"></script>
<script type="text/javascript">
let height = function () { return document.height || document.body.offsetHeight; };
new Postmate({ height }).then(() => console.log('Host Page Ready'));
new Postmate({ ccToken }).then(() => console.log('Host Page Ready'));
</script>
</body>
</html>
24 changes: 21 additions & 3 deletions lib/postmate.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@

/**
* The type of messages our frames our sending
* @type {String}
*/
const MESSAGE_TYPE = 'application/x-postmate-v1+json';

/**
* Postmate logging function that enables/disables via config
* @param {Object} ...args Rest Arguments
* @return {undefined}
*/
function log(...args) {
console.log(...args); // eslint-disable-line no-console
}

/**
* Takes a context, and searches for a value located by the key
* Takes a context, and searches for a value by the key
* @param {Object} context The dictionary to search against
* @param {String} key A path within a dictionary (i.e. 'window.location.href')
* @return {Promise}
Expand All @@ -18,7 +27,7 @@ function resolveValue(context, key, data) {

/**
* Composes an API namespace for the respective client or host
* @param {Object} data Information on the consumer
* @param {Object} info Information on the consumer
*/
function Consumer(info) {
const { id, context, client, frame, host } = info;
Expand Down Expand Up @@ -74,7 +83,11 @@ function Consumer(info) {
}
}

// HOST
/**
* The entry point of the Host. Exposes a context, or set of properties that the
* Client may interact with.
* @param {Object} context Hash of values, functions, or promises
*/
function Postmate(context) {
this.id = 'host';
this.host = window;
Expand All @@ -99,6 +112,10 @@ function Postmate(context) {
});
}

/**
* The entry point of the Client. Begins the handshake strategy
* @param {Object} userOptions The element to inject the frame into, and the url
*/
Postmate.Handshake = function Handshake(userOptions) {
const { container, url } = userOptions;

Expand Down Expand Up @@ -134,4 +151,5 @@ Postmate.Handshake = function Handshake(userOptions) {
});
};

// Export
export default Postmate;
40 changes: 27 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
{
"name": "postmate.js",
"version": "1.0.0",
"description": "",
"main": "postmate.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "python -m SimpleHTTPServer 4000",
"build": "gulp build",
"lint": "gulp lint"
},
"author": "",
"license": "ISC",
"name": "postmate",
"version": "0.1.0",
"description": "A powerful, simple, promise-based postMessage library",
"main": "lib/postmate.js",
"devDependencies": {
"babel-preset-es2015-rollup": "^1.1.1",
"eslint-config-airbnb": "^9.0.1",
Expand All @@ -22,5 +14,27 @@
"rollup-stream": "^1.11.0",
"uglify-js": "^2.7.0",
"vinyl-source-stream": "^1.1.0"
}
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "python -m SimpleHTTPServer 4000",
"build": "gulp build",
"lint": "gulp lint"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dollarshaveclub/postmate.git"
},
"keywords": [
"postMessage",
"secure",
"handshake",
"promise"
],
"author": "Jacob Kelley <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/dollarshaveclub/postmate/issues"
},
"homepage": "https://github.com/dollarshaveclub/postmate#readme"
}

0 comments on commit 482de29

Please sign in to comment.