Skip to content

Commit 798d6ce

Browse files
authored
Merge pull request #4 from secondstreet/typescript
♻️ Rewrite in TypeScript
2 parents 9e99450 + 1596de2 commit 798d6ce

39 files changed

+4682
-447
lines changed

.circleci/config.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Javascript Node CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
build:
8+
docker:
9+
# specify the version you desire here
10+
- image: circleci/node:10.14.0
11+
12+
# Specify service dependencies here if necessary
13+
# CircleCI maintains a library of pre-built images
14+
# documented at https://circleci.com/docs/2.0/circleci-images/
15+
# - image: circleci/mongo:3.4.4
16+
17+
working_directory: ~/repo
18+
19+
steps:
20+
- checkout
21+
22+
# Download and cache dependencies
23+
- restore_cache:
24+
keys:
25+
- v1-dependencies-{{ checksum "yarn.lock" }}
26+
# fallback to using the latest cache if no exact match is found
27+
- v1-dependencies-
28+
29+
- run: yarn install
30+
31+
- save_cache:
32+
paths:
33+
- node_modules
34+
key: v1-dependencies-{{ checksum "yarn.lock" }}
35+
36+
# run tests!
37+
- run: yarn test

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v10.14.0

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"printWidth": 120,
4+
"trailingComma": "es5"
5+
}

README.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
talker.js
2-
=========
1+
# talker.js
32

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

6-
Documentation
7-
-------------
5+
## Documentation
86

97
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.
108

11-
Building
12-
--------
9+
## Building
1310

1411
```
15-
npm install -g grunt-cli
16-
npm install
17-
grunt
12+
yarn install
13+
yarn run build
1814
```

bower.json

+3-17
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,8 @@
55
"author": "Second Street <[email protected]>",
66
"description": "A tiny, promise-based library for cross-origin communication between frames and windows.",
77
"main": "./dist/talker.min.js",
8-
"moduleType": [
9-
"globals"
10-
],
11-
"keywords": [
12-
"iframe",
13-
"postMessage",
14-
"cross-domain",
15-
"cross-origin",
16-
"promise"
17-
],
8+
"moduleType": ["globals"],
9+
"keywords": ["iframe", "postMessage", "cross-domain", "cross-origin", "promise"],
1810
"license": "MIT",
19-
"ignore": [
20-
"**/.*",
21-
"node_modules",
22-
"bower_components",
23-
"test",
24-
"tests"
25-
]
11+
"ignore": ["**/.*", "node_modules", "bower_components", "test", "tests"]
2612
}

dist/amd/talker.min.js

+9-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/amd/talker.min.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/common_js/talker.min.js

+8-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/common_js/talker.min.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/constants.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export declare const TALKER_CONTENT_TYPE: string;
2+
export declare const TALKER_ERR_MSG_TIMEOUT: string;

dist/constants.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/constants.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.d.ts

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { ManipulablePromise } from "./utils/manipulable-promise";
2+
import { IncomingMessage, OutgoingMessage, Stringifyable } from "./message";
3+
/**
4+
* Talker
5+
* Opens a communication line between this window and a remote window via postMessage.
6+
*/
7+
declare class Talker {
8+
private readonly remoteWindow;
9+
private readonly remoteOrigin;
10+
private readonly localWindow;
11+
timeout: number;
12+
/**
13+
* @property onMessage - Will be called with every non-handshake, non-response message from the remote window
14+
*/
15+
onMessage?: (message: IncomingMessage) => void;
16+
private readonly handshake;
17+
private handshaken;
18+
private latestId;
19+
private readonly queue;
20+
private readonly sent;
21+
/**
22+
* @param remoteWindow - The remote `window` object to post/receive messages to/from
23+
* @param remoteOrigin - The protocol, host, and port you expect the remoteWindow to be
24+
* @param localWindow - The local `window` object
25+
*/
26+
constructor(remoteWindow: Window, remoteOrigin: string, localWindow?: Window);
27+
/**
28+
* @param namespace - The namespace the message is in
29+
* @param data - The data to send
30+
* @param responseToId - If this is a response to a previous message, its ID.
31+
*/
32+
send(namespace: string, data: Stringifyable, responseToId?: number | null): ManipulablePromise<IncomingMessage | Error>;
33+
/**
34+
* This is not marked private because other Talker-related classes need access to it,
35+
* but your application code should probably avoid calling this method.
36+
*/
37+
nextId(): number;
38+
private receiveMessage;
39+
/**
40+
* Determines whether it is safe and appropriate to parse a postMessage messageEvent
41+
* @param source - "source" property from the postMessage event
42+
* @param origin - Protocol, host, and port
43+
* @param type - Internet Media Type
44+
*/
45+
private isSafeMessage;
46+
private handleHandshake;
47+
private handleMessage;
48+
/**
49+
* @param id - Message ID of the waiting promise
50+
* @param message - Message that is responding to that ID
51+
*/
52+
private respondToMessage;
53+
/**
54+
* Send a non-response message to awaiting hooks/callbacks
55+
* @param message - Message that arrived
56+
*/
57+
private broadcastMessage;
58+
/**
59+
* Send a handshake message to the remote window
60+
* @param confirmation - Is this a confirmation handshake?
61+
*/
62+
private sendHandshake;
63+
/**
64+
* Wrapper around window.postMessage to only send if we have the necessary objects
65+
*/
66+
private postMessage;
67+
/**
68+
* Flushes the internal queue of outgoing messages, sending each one.
69+
* Does nothing if Talker has not handshaken with the remote.
70+
*/
71+
private flushQueue;
72+
}
73+
export { IncomingMessage, OutgoingMessage };
74+
export default Talker;

dist/index.js

+181
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)