-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
68 additions
and
137 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const ORIGIN_CI = 'http://project.ci' | ||
const ORIGIN_PROD = 'https://www.teambition.com' | ||
|
||
export type IframeMessageType = { | ||
method: string | ||
params: any | ||
|
||
isCI?: boolean | ||
origin: string | ||
toOrigin?: string | ||
|
||
onSuccess?(): void | ||
onError?({ error: any }): void | ||
} | ||
|
||
export const notify = (args) => callService({ ...args, method: 'essage' }) | ||
|
||
export const callService = ({ | ||
isCI, | ||
toOrigin = isCI ? ORIGIN_CI : ORIGIN_PROD, | ||
...data | ||
}: IframeMessageType) => | ||
window.parent.postMessage(JSON.parse(JSON.stringify(data)), toOrigin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,26 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var ORIGIN_CI = 'http://project.ci'; | ||
var ORIGIN_PROD = 'https://www.teambition.com'; | ||
|
||
var toggleEventListener = function toggleEventListener(callback, isRemove) { | ||
var func = isRemove ? 'removeEventListener' : 'addEventListener'; | ||
return window[func]('message', callback, false); | ||
}; | ||
|
||
var consoleError = function consoleError(_ref) { | ||
var error = _ref.error; | ||
|
||
var errorMessage = error || 'ERROR'; | ||
return console.error(errorMessage); | ||
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
|
||
var notify = function notify(_ref2) { | ||
var isCI = _ref2.isCI, | ||
origin = _ref2.origin, | ||
onError = _ref2.onError, | ||
onSuccess = _ref2.onSuccess, | ||
params = _ref2.params; | ||
|
||
callService({ | ||
isCI: isCI, | ||
origin: origin, | ||
params: params, | ||
onSuccess: onSuccess, | ||
onError: onError, | ||
method: 'essage' | ||
}); | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
|
||
var callService = function callService(_ref3) { | ||
var isCI = _ref3.isCI, | ||
method = _ref3.method, | ||
params = _ref3.params, | ||
onSuccess = _ref3.onSuccess, | ||
onError = _ref3.onError, | ||
fromOrigin = _ref3.origin, | ||
toOrigin = _ref3.toOrigin; | ||
|
||
var postId = Date.now(); | ||
var targetOrigin = toOrigin || (isCI ? ORIGIN_CI : ORIGIN_PROD); | ||
var content = { method: method, params: params, postId: postId, origin: fromOrigin }; | ||
window.parent.postMessage(content, targetOrigin); | ||
var callback = function callback(_ref4) { | ||
var data = _ref4.data; | ||
|
||
if (postId !== data.postId) return; | ||
if (data.error) { | ||
onError = onError || consoleError; | ||
onError(data); | ||
} else { | ||
if (typeof onSuccess === "function") { | ||
onSuccess(data); | ||
} | ||
} | ||
toggleEventListener(callback, true); | ||
}; | ||
toggleEventListener(callback); | ||
exports.__esModule = true; | ||
var ORIGIN_CI = 'http://project.ci'; | ||
var ORIGIN_PROD = 'https://www.teambition.com'; | ||
exports.notify = function (args) { return exports.callService(__assign({}, args, { method: 'essage' })); }; | ||
exports.callService = function (_a) { | ||
var isCI = _a.isCI, _b = _a.toOrigin, toOrigin = _b === void 0 ? isCI ? ORIGIN_CI : ORIGIN_PROD : _b, data = __rest(_a, ["isCI", "toOrigin"]); | ||
return window.parent.postMessage(JSON.parse(JSON.stringify(data)), toOrigin); | ||
}; | ||
|
||
exports.notify = notify; | ||
exports.callService = callService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./lib", | ||
"allowJs": true, | ||
"checkJs": false, | ||
"module": "commonjs", | ||
"target": "es5", | ||
"jsx": "react", | ||
"moduleResolution": "node", | ||
"lib": ["es2015", "dom"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
typescript@^2.8.3: | ||
version "2.8.3" | ||
resolved "http://r.cnpmjs.org/typescript/download/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170" |