Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Rewrite in TypeScript #4

Merged
merged 12 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:10.14.0

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/mongo:3.4.4

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: yarn install

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "yarn.lock" }}

# run tests!
- run: yarn test
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v10.14.0
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"printWidth": 120,
"trailingComma": "es5"
}
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
talker.js
=========
# talker.js

A tiny (<4kB minified, <1kB min+gzip), promise-based library for cross-origin communication between frames and windows.
A small (<13kB minified, <6kB min+gzip), promise-based library for cross-origin communication between frames and windows.

Documentation
-------------
## Documentation

Please see [drive.secondstreet.com/introducing-talker](http://drive.secondstreet.com/introducing-talker/) for instructions and examples for using Talker.js in your own projects.

Building
--------
## Building

```
npm install -g grunt-cli
npm install
grunt
yarn install
yarn run build
```
20 changes: 3 additions & 17 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,8 @@
"author": "Second Street <development@secondstreet.com>",
"description": "A tiny, promise-based library for cross-origin communication between frames and windows.",
"main": "./dist/talker.min.js",
"moduleType": [
"globals"
],
"keywords": [
"iframe",
"postMessage",
"cross-domain",
"cross-origin",
"promise"
],
"moduleType": ["globals"],
"keywords": ["iframe", "postMessage", "cross-domain", "cross-origin", "promise"],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
"ignore": ["**/.*", "node_modules", "bower_components", "test", "tests"]
}
15 changes: 9 additions & 6 deletions dist/amd/talker.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/amd/talker.min.js.map

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions dist/common_js/talker.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/common_js/talker.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare const TALKER_CONTENT_TYPE: string;
export declare const TALKER_ERR_MSG_TIMEOUT: string;
3 changes: 3 additions & 0 deletions dist/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/constants.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { ManipulablePromise } from "./utils/manipulable-promise";
import { IncomingMessage, OutgoingMessage, Stringifyable } from "./message";
/**
* Talker
* Opens a communication line between this window and a remote window via postMessage.
*/
declare class Talker {
private readonly remoteWindow;
private readonly remoteOrigin;
private readonly localWindow;
timeout: number;
/**
* @property onMessage - Will be called with every non-handshake, non-response message from the remote window
*/
onMessage?: (message: IncomingMessage) => void;
private readonly handshake;
private handshaken;
private latestId;
private readonly queue;
private readonly sent;
/**
* @param remoteWindow - The remote `window` object to post/receive messages to/from
* @param remoteOrigin - The protocol, host, and port you expect the remoteWindow to be
* @param localWindow - The local `window` object
*/
constructor(remoteWindow: Window, remoteOrigin: string, localWindow?: Window);
/**
* @param namespace - The namespace the message is in
* @param data - The data to send
* @param responseToId - If this is a response to a previous message, its ID.
*/
send(namespace: string, data: Stringifyable, responseToId?: number | null): ManipulablePromise<IncomingMessage | Error>;
/**
* This is not marked private because other Talker-related classes need access to it,
* but your application code should probably avoid calling this method.
*/
nextId(): number;
private receiveMessage;
/**
* Determines whether it is safe and appropriate to parse a postMessage messageEvent
* @param source - "source" property from the postMessage event
* @param origin - Protocol, host, and port
* @param type - Internet Media Type
*/
private isSafeMessage;
private handleHandshake;
private handleMessage;
/**
* @param id - Message ID of the waiting promise
* @param message - Message that is responding to that ID
*/
private respondToMessage;
/**
* Send a non-response message to awaiting hooks/callbacks
* @param message - Message that arrived
*/
private broadcastMessage;
/**
* Send a handshake message to the remote window
* @param confirmation - Is this a confirmation handshake?
*/
private sendHandshake;
/**
* Wrapper around window.postMessage to only send if we have the necessary objects
*/
private postMessage;
/**
* Flushes the internal queue of outgoing messages, sending each one.
* Does nothing if Talker has not handshaken with the remote.
*/
private flushQueue;
}
export { IncomingMessage, OutgoingMessage };
export default Talker;
181 changes: 181 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading