-
Notifications
You must be signed in to change notification settings - Fork 11
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
41 changed files
with
4,147 additions
and
2,671 deletions.
There are no files selected for viewing
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 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 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 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,58 @@ | ||
# Addressable | ||
|
||
A lightweight standalone micro lib to create addressable post messages. | ||
Let say you have some post messages on the main thread a couple of IFrames and a few web workers. | ||
Sending message between this element will be a nightmare! | ||
|
||
The solution, **addresses** like a plan tcp/ip network, or the WEB | ||
|
||
- This package is independent it maintained under scalecube-js only for convenience. | ||
|
||
# API | ||
|
||
Add thread to network; you must add it to main thread in order iframe/workers will work | ||
|
||
```ts | ||
import '@scalecube/addressable'; | ||
``` | ||
|
||
listen for messages on address | ||
|
||
```ts | ||
import {listen} from '@scalecube/addressable'; | ||
listen("address", (msg, port: MessagePort)=>{port.postMessage("pong")}); | ||
``` | ||
|
||
connect to address | ||
|
||
```ts | ||
import {connect} from '@scalecube/addressable'; | ||
const port = connect("address"); | ||
port.addEventListener("message", console.log); | ||
port.postMessage("ping"); | ||
``` | ||
|
||
Cleaning connections | ||
```ts | ||
import {connect, listen} from '@scalecube/addressable'; | ||
listen("address", (msg, port: MessagePort) => { | ||
if( msg === "ping" ) { | ||
port.postMessage("pong"); | ||
} else if (msg === "close") { | ||
port.close(); | ||
} | ||
}); | ||
|
||
const port = connect("address"); | ||
port.addEventListener("message", console.log); | ||
port.postMessage("ping"); | ||
port.postMessage("close"); | ||
port.close(); | ||
``` | ||
|
||
# How it's works | ||
|
||
- Each time you import addressable it will create global event listener in each thread | ||
- Threads will register them self by sending a message to main thread | ||
- Each time new listener added it will spread to main thread and to all thread from there | ||
- When connect is called it will create a message channel and give a port to listen callback and open side |
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,3 @@ | ||
require('./e2eStart'); | ||
|
||
module.exports = require('jest-environment-puppeteer').setup; |
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 @@ | ||
const { exec } = require('child_process'); | ||
|
||
const start = exec('yarn start', { cwd: '../../' }); | ||
|
||
module.exports = { | ||
start, | ||
}; |
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,3 @@ | ||
const p = require('./e2eStart'); | ||
p.start.kill('SIGQUIT'); | ||
module.exports = require('jest-environment-puppeteer').teardown; |
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,6 @@ | ||
module.exports = { | ||
testRegex: '(\\.|/)browser\\.ts$', | ||
preset: 'jest-puppeteer', | ||
globalSetup: './e2eSetup.js', | ||
globalTeardown: './e2eTeardown.js', | ||
}; |
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,13 @@ | ||
module.exports = { | ||
transform: { | ||
'.(ts|tsx)': 'ts-jest', | ||
}, | ||
testRegex: '(\\.|/)spec\\.ts$', | ||
testPathIgnorePatterns: ['<rootDir>/es/', '<rootDir>/lib/', '<rootDir>/node_modules/'], | ||
moduleFileExtensions: ['ts', 'tsx', 'js'], | ||
moduleDirectories: ['node_modules', 'src'], | ||
globals: { | ||
isNodeEvn: false, | ||
}, | ||
setupFilesAfterEnv: ['<rootDir>/tests/messageChannelMock.ts'], | ||
}; |
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,51 @@ | ||
{ | ||
"name": "@scalecube/addressable", | ||
"version": "0.2.9", | ||
"private": false, | ||
"unpkg": "dist/index.js", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib", | ||
"dist" | ||
], | ||
"license": "MIT", | ||
"scripts": { | ||
"clean": "rimraf node_modules && rimraf .cache && rimraf lib && rimraf es", | ||
"build": "rimraf .cache && yarn build:dist && yarn build:cjs", | ||
"build:dist": "rimraf dist && rollup -c rollup.iife.config.js", | ||
"build:cjs": "rimraf lib && rollup -c rollup.cjs.config.js", | ||
"fixture": "yarn build && yarn fixture:build", | ||
"fixture:build": "rimraf tests/fixtures/pingPong/dist && parcel build tests/fixtures/pingPong/pingPong.ts --no-source-maps --experimental-scope-hoisting --out-dir tests/fixtures/pingPong/dist", | ||
"lint": "tslint '{src,tests}/**/*.{ts,tsx}' --fix", | ||
"prettier": "prettier --write '{src,tests}/**/*.{ts,tsx}'", | ||
"test": "yarn test:unit && yarn test:browser", | ||
"test:unit": "jest --config jest.config.js", | ||
"test:browser": "yarn fixture && jest --forceExit --config jest-puppeteer.config.js", | ||
"doc": "typedoc ./src --out ./doc --mode file --name 'Scalecube API' --hideGenerator --readme ./README.md" | ||
}, | ||
"author": "Scalecube (https://github.com/scalecube/scalecube-js)", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@scalecube/utils": "^0.2.9", | ||
"@types/expect-puppeteer": "^4.4.3", | ||
"@types/jest-environment-puppeteer": "^4.3.2", | ||
"@types/puppeteer": "^3.0.1", | ||
"jest-puppeteer": "^4.4.0", | ||
"puppeteer": "^5.2.1", | ||
"rollup": "^1.27.4", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-filesize": "^6.1.1", | ||
"rollup-plugin-node-globals": "^1.4.0", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-terser": "^5.3.0", | ||
"rollup-plugin-typescript2": "^0.27.1", | ||
"rollup-plugin-uglify-es": "^0.0.1", | ||
"rollup-plugin-visualizer": "^2.6.0", | ||
"tslint": "^5.11.0", | ||
"typedoc": "^0.14.2", | ||
"typescript": "^3.2.4" | ||
} | ||
} |
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,58 @@ | ||
import visualizer from 'rollup-plugin-visualizer'; | ||
import typescript from 'rollup-plugin-typescript2'; | ||
import tscompile from 'typescript'; | ||
import filesize from 'rollup-plugin-filesize'; | ||
import resolve from 'rollup-plugin-node-resolve'; | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
import pkg from './package.json'; | ||
import babel from 'rollup-plugin-babel'; | ||
|
||
export default { | ||
input: 'src/index.ts', | ||
output: [ | ||
{ | ||
file: pkg.main, | ||
format: 'cjs', | ||
sourcemap: false, | ||
}, | ||
], | ||
plugins: [ | ||
commonjs({ | ||
include: /node_modules/, | ||
browser: true, | ||
namedExports: { | ||
'rsocket-types': ['CONNECTION_STATUS'], | ||
}, | ||
}), | ||
resolve(), | ||
babel({ | ||
plugins: ['@babel/plugin-transform-arrow-functions'], | ||
babelrc: false, | ||
runtimeHelpers: true, | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
spec: true, | ||
forceAllTransforms: true, | ||
targets: { | ||
chrome: '29', | ||
ie: '11', | ||
}, | ||
}, | ||
], | ||
], | ||
}), | ||
visualizer({ | ||
filename: 'report.cjs.html', | ||
title: 'Browser - cjs', | ||
}), | ||
typescript({ | ||
typescript: tscompile, | ||
clean: true, | ||
}), | ||
// global(), | ||
filesize(), | ||
], | ||
}; |
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,61 @@ | ||
import visualizer from 'rollup-plugin-visualizer'; | ||
import typescript from 'rollup-plugin-typescript2'; | ||
import tscompile from 'typescript'; | ||
import filesize from 'rollup-plugin-filesize'; | ||
import resolve from 'rollup-plugin-node-resolve'; | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
import pkg from './package.json'; | ||
import replace from 'rollup-plugin-replace'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
import babel from 'rollup-plugin-babel'; | ||
|
||
export default { | ||
input: 'src/index.ts', | ||
output: [ | ||
{ | ||
name: 'sc', | ||
file: pkg.unpkg, | ||
format: 'iife', | ||
sourcemap: false, | ||
}, | ||
], | ||
plugins: [ | ||
commonjs({ | ||
include: /node_modules/, | ||
browser: true, | ||
}), | ||
resolve(), | ||
babel({ | ||
plugins: ['@babel/plugin-transform-arrow-functions'], | ||
babelrc: true, | ||
runtimeHelpers: true, | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
spec: true, | ||
forceAllTransforms: true, | ||
targets: { | ||
chrome: '29', | ||
ie: '11', | ||
}, | ||
}, | ||
], | ||
], | ||
}), | ||
replace({ | ||
'process.env.NODE_ENV': JSON.stringify('production'), | ||
}), | ||
visualizer({ | ||
filename: 'report.iffe.html', | ||
title: 'Microservice - iife', | ||
}), | ||
typescript({ | ||
typescript: tscompile, | ||
clean: true, | ||
}), | ||
terser(), | ||
filesize(), | ||
], | ||
}; |
Oops, something went wrong.