Skip to content

Commit

Permalink
refactor(webSocket): rename back to webSocket ala 5.0 (#3590)
Browse files Browse the repository at this point in the history
* refactor(webSocket): rename back to webSocket ala 5.0

BREAKING CHANGE: UNBREAKING websocket to be named `webSocket` again, just like it was in 5.0. Now you should import from `rxjs/webSocket`

* refactor(webSocket): update tsconfig files

* refactor(webSocket): update ./make-packages.js

* refactor(webSocket): update webSocket for systemjs
  • Loading branch information
benlesh authored Apr 20, 2018
1 parent f4d7d02 commit d5658fe
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .make-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fs.copySync('./tsconfig.base.json', PKG_ROOT + 'src/tsconfig.json');
fs.writeJsonSync(PKG_ROOT + 'package.json', rootPackageJson, {spaces: 2});
fs.copySync('src/operators/package.json', PKG_ROOT + '/operators/package.json');
fs.copySync('src/ajax/package.json', PKG_ROOT + '/ajax/package.json');
fs.copySync('src/websocket/package.json', PKG_ROOT + '/websocket/package.json');
fs.copySync('src/webSocket/package.json', PKG_ROOT + '/webSocket/package.json');
fs.copySync('src/testing/package.json', PKG_ROOT + '/testing/package.json');
fs.copySync('src/internal-compatibility/package.json', PKG_ROOT + '/internal-compatibility/package.json');

Expand Down
2 changes: 1 addition & 1 deletion MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Other export points:

- `rxjs/testing`: The `TestScheduler` and friends can be found here
- `rxjs/ajax`: This is the new home for the rxjs AJAX implementation
- `rxjs/websocket`: This is the home for the rxjs web socket implementation.
- `rxjs/webSocket`: This is the home for the rxjs web socket implementation.


### Import Migration Table
Expand Down
2 changes: 1 addition & 1 deletion compat/add/observable/dom/webSocket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Observable } from 'rxjs';
import { websocket as staticWebSocket } from 'rxjs/websocket';
import { webSocket as staticWebSocket } from 'rxjs/webSocket';

Observable.webSocket = staticWebSocket;

Expand Down
4 changes: 2 additions & 2 deletions integration/systemjs/systemjs-compatibility-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ System.config({
'rxjs/ajax': {main: 'index.js', defaultExtension: 'js' },
'rxjs/operators': {main: 'index.js', defaultExtension: 'js' },
'rxjs/testing': {main: 'index.js', defaultExtension: 'js' },
'rxjs/websocket': {main: 'index.js', defaultExtension: 'js' }
'rxjs/webSocket': {main: 'index.js', defaultExtension: 'js' }
}
});

Expand All @@ -17,7 +17,7 @@ Promise.all([
System.import('rxjs/ajax'),
System.import('rxjs/operators'),
System.import('rxjs/testing'),
System.import('rxjs/websocket'),
System.import('rxjs/webSocket'),
]).then(
function () { console.log('Successfully tested all entry-points with SystemJS!'); },
function (error) {
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

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

52 changes: 26 additions & 26 deletions spec/observables/dom/webSocket-spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expect } from 'chai';
import * as sinon from 'sinon';
import { websocket } from 'rxjs/websocket';
import { webSocket } from 'rxjs/webSocket';
import { map, retry, take, repeat, takeWhile } from 'rxjs/operators';

declare const __root__: any;

/** @test {webSocket} */
describe('websocket', () => {
describe('webSocket', () => {
let __ws: any;

function setupMockWebSocket() {
Expand All @@ -30,7 +30,7 @@ describe('websocket', () => {

it('should send and receive messages', () => {
let messageReceived = false;
const subject = websocket<string>('ws://mysocket');
const subject = webSocket<string>('ws://mysocket');

subject.next('ping');

Expand All @@ -52,7 +52,7 @@ describe('websocket', () => {
});

it('should allow use of operators and subscribe', () => {
const subject = websocket<string>('ws://mysocket');
const subject = webSocket<string>('ws://mysocket');
const results: any[] = [];

subject.pipe(
Expand All @@ -68,7 +68,7 @@ describe('websocket', () => {
it('receive multiple messages', () => {
const expected = ['what', 'do', 'you', 'do', 'with', 'a', 'drunken', 'sailor?'];
const results: string[] = [];
const subject = websocket<string>('ws://mysocket');
const subject = webSocket<string>('ws://mysocket');

subject.subscribe(x => {
results.push(x);
Expand All @@ -89,7 +89,7 @@ describe('websocket', () => {

it('should queue messages prior to subscription', () => {
const expected = ['make', 'him', 'walk', 'the', 'plank'];
const subject = websocket<string>('ws://mysocket');
const subject = webSocket<string>('ws://mysocket');

expected.forEach(x => {
subject.next(x);
Expand All @@ -110,7 +110,7 @@ describe('websocket', () => {
});

it('should send messages immediately if already open', () => {
const subject = websocket<string>('ws://mysocket');
const subject = webSocket<string>('ws://mysocket');
subject.subscribe();
const socket = MockWebSocket.lastSocket;
socket.open();
Expand All @@ -124,7 +124,7 @@ describe('websocket', () => {
});

it('should close the socket when completed', () => {
const subject = websocket<string>('ws://mysocket');
const subject = webSocket<string>('ws://mysocket');
subject.subscribe();
const socket = MockWebSocket.lastSocket;
socket.open();
Expand All @@ -144,7 +144,7 @@ describe('websocket', () => {
});

it('should close the socket with a code and a reason when errored', () => {
const subject = websocket<string>('ws://mysocket');
const subject = webSocket<string>('ws://mysocket');
subject.subscribe();
const socket = MockWebSocket.lastSocket;
socket.open();
Expand All @@ -160,7 +160,7 @@ describe('websocket', () => {
});

it('should allow resubscription after closure via complete', () => {
const subject = websocket<string>('ws://mysocket');
const subject = webSocket<string>('ws://mysocket');
subject.subscribe();
const socket1 = MockWebSocket.lastSocket;
socket1.open();
Expand All @@ -178,7 +178,7 @@ describe('websocket', () => {
});

it('should allow resubscription after closure via error', () => {
const subject = websocket<string>('ws://mysocket');
const subject = webSocket<string>('ws://mysocket');
subject.subscribe();
const socket1 = MockWebSocket.lastSocket;
socket1.open();
Expand All @@ -198,7 +198,7 @@ describe('websocket', () => {
it('should have a default resultSelector that parses message data as JSON', () => {
let result;
const expected = { mork: 'shazbot!' };
const subject = websocket<string>('ws://mysocket');
const subject = webSocket<string>('ws://mysocket');

subject.subscribe((x: any) => {
result = x;
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('websocket', () => {

it('should send and receive messages', () => {
let messageReceived = false;
const subject = websocket<string>({ url: 'ws://mysocket' });
const subject = webSocket<string>({ url: 'ws://mysocket' });

subject.next('ping');

Expand All @@ -248,7 +248,7 @@ describe('websocket', () => {
});

it('should take a protocol and set it properly on the web socket', () => {
const subject = websocket<string>({
const subject = webSocket<string>({
url: 'ws://mysocket',
protocol: 'someprotocol'
});
Expand All @@ -262,7 +262,7 @@ describe('websocket', () => {
});

it('should take a binaryType and set it properly on the web socket', () => {
const subject = websocket<string>({
const subject = webSocket<string>({
url: 'ws://mysocket',
binaryType: 'blob'
});
Expand All @@ -278,7 +278,7 @@ describe('websocket', () => {
it('should take a deserializer', () => {
const results = [] as string[];

const subject = websocket<string>({
const subject = webSocket<string>({
url: 'ws://mysocket',
deserializer: (e: any) => {
return e.data + '!';
Expand All @@ -301,7 +301,7 @@ describe('websocket', () => {
});

it('if the deserializer fails it should go down the error path', () => {
const subject = websocket<string>({
const subject = webSocket<string>({
url: 'ws://mysocket',
deserializer: (e: any) => {
throw new Error('I am a bad error');
Expand All @@ -323,7 +323,7 @@ describe('websocket', () => {

it('should accept a closingObserver', () => {
let calls = 0;
const subject = websocket<string>(<any>{
const subject = webSocket<string>(<any>{
url: 'ws://mysocket',
closingObserver: {
next(x: any) {
Expand Down Expand Up @@ -355,7 +355,7 @@ describe('websocket', () => {
it('should accept a closeObserver', () => {
const expected = [{ wasClean: true }, { wasClean: false }];
const closes = [] as any[];
const subject = websocket<string>(<any>{
const subject = webSocket<string>(<any>{
url: 'ws://mysocket',
closeObserver: {
next(e: any) {
Expand Down Expand Up @@ -390,7 +390,7 @@ describe('websocket', () => {
});

it('should handle constructor errors', () => {
const subject = websocket<string>(<any>{
const subject = webSocket<string>(<any>{
url: 'bad_url',
WebSocketCtor: (url: string, protocol?: string | string[]): WebSocket => {
throw new Error(`connection refused`);
Expand Down Expand Up @@ -419,7 +419,7 @@ describe('websocket', () => {

it('should be retryable', () => {
const results = [] as string[];
const subject = websocket<{ name: string, value: string }>('ws://websocket');
const subject = webSocket<{ name: string, value: string }>('ws://websocket');
const source = subject.multiplex(
() => ({ sub: 'foo' }),
() => ({ unsub: 'foo' }),
Expand Down Expand Up @@ -454,7 +454,7 @@ describe('websocket', () => {

it('should be repeatable', () => {
const results = [] as string[];
const subject = websocket<{ name: string, value: string }>('ws://websocket');
const subject = webSocket<{ name: string, value: string }>('ws://websocket');
const source = subject.multiplex(
() => ({ sub: 'foo' }),
() => ({ unsub: 'foo' }),
Expand Down Expand Up @@ -490,9 +490,9 @@ describe('websocket', () => {
expect(results).to.deep.equal(['test', 'this', 'test', 'this'], 'results were not equal');
});

it('should multiplex over the websocket', () => {
it('should multiplex over the webSocket', () => {
const results = [] as Array<{ value: number, name: string }>;
const subject = websocket<{ value: number, name: string }>('ws://websocket');
const subject = webSocket<{ value: number, name: string }>('ws://websocket');
const source = subject.multiplex(
() => ({ sub: 'foo'}),
() => ({ unsub: 'foo' }),
Expand Down Expand Up @@ -527,7 +527,7 @@ describe('websocket', () => {
});

it('should keep the same socket for multiple multiplex subscriptions', () => {
const socketSubject = websocket<string>({url: 'ws://mysocket'});
const socketSubject = webSocket<string>({url: 'ws://mysocket'});
const results = [] as string[];
const socketMessages = [
{id: 'A'},
Expand Down Expand Up @@ -584,7 +584,7 @@ describe('websocket', () => {
});

it('should not close the socket until all subscriptions complete', () => {
const socketSubject = websocket<{ id: string, complete: boolean }>({url: 'ws://mysocket'});
const socketSubject = webSocket<{ id: string, complete: boolean }>({url: 'ws://mysocket'});
const results = [] as string[];
const socketMessages = [
{id: 'A'},
Expand Down
4 changes: 2 additions & 2 deletions spec/websocket/index-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as index from 'rxjs/websocket';
import * as index from 'rxjs/webSocket';
import { expect } from 'chai';

describe('index', () => {
it('should export static websocket subject creator functions', () => {
expect(index.websocket).to.exist;
expect(index.webSocket).to.exist;
});
});
2 changes: 1 addition & 1 deletion src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ ts_library(
"//ajax",
"//operators",
"//testing",
"//websocket",
"//webSocket",
],
)
2 changes: 1 addition & 1 deletion src/internal/observable/dom/WebSocketSubject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface WebSocketSubjectConfig<T> {
*/
openObserver?: NextObserver<Event>;
/**
* An Observer than watches when close events occur on the underlying websocket
* An Observer than watches when close events occur on the underlying webSocket
*/
closeObserver?: NextObserver<CloseEvent>;
/**
Expand Down
12 changes: 6 additions & 6 deletions src/internal/observable/dom/webSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject';
*
* @example <caption>Wraps browser WebSocket</caption>
*
* import { webSocket } from 'rxjs/websocket';
* import { webSocket } from 'rxjs/webSocket';
*
* let socket$ = webSocket('ws://localhost:8081');
*
Expand All @@ -17,14 +17,14 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject';
*
* socket$.next(JSON.stringify({ op: 'hello' }));
*
* @example <caption>Wraps WebSocket from nodejs-websocket (using node.js)</caption>
* @example <caption>Wraps WebSocket from nodejs-webSocket (using node.js)</caption>
*
* import { webSocket } from 'rxjs/websocket';
* import { w3cwebsocket } from 'websocket';
* import { webSocket } from 'rxjs/webSocket';
* import { w3cwebSocket } from 'webSocket';
*
* let socket$ = webSocket({
* url: 'ws://localhost:8081',
* WebSocketCtor: w3cwebsocket
* WebSocketCtor: w3cwebSocket
* });
*
* socket$.subscribe(
Expand All @@ -35,7 +35,7 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject';
*
* socket$.next(JSON.stringify({ op: 'hello' }));
*
* @param {string | WebSocketSubjectConfig} urlConfigOrSource the source of the websocket as an url or a structure defining the websocket object
* @param {string | WebSocketSubjectConfig} urlConfigOrSource the source of the webSocket as an url or a structure defining the webSocket object
* @return {WebSocketSubject}
*/
export function webSocket<T>(urlConfigOrSource: string | WebSocketSubjectConfig<T>): WebSocketSubject<T> {
Expand Down
6 changes: 3 additions & 3 deletions src/internal/umd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export const testing = _testing;
import * as _ajax from '../ajax/index';
export const ajax = _ajax;

/* rxjs.websocket */
import * as _websocket from '../websocket/index';
export const websocket = _websocket;
/* rxjs.webSocket */
import * as _webSocket from '../webSocket/index';
export const webSocket = _webSocket;
4 changes: 2 additions & 2 deletions src/websocket/BUILD.bazel → src/webSocket/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")

ts_library(
name = "websocket",
name = "webSocket",
srcs = ["index.ts"],
module_name = "rxjs/websocket",
module_name = "rxjs/webSocket",
module_root = "index.d.ts",
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
tsconfig = "//:tsconfig.json",
Expand Down
2 changes: 1 addition & 1 deletion src/websocket/index.ts → src/webSocket/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { webSocket as websocket } from '../internal/observable/dom/webSocket';
export { webSocket as webSocket } from '../internal/observable/dom/webSocket';
export { WebSocketSubject, WebSocketSubjectConfig } from '../internal/observable/dom/WebSocketSubject';
8 changes: 8 additions & 0 deletions src/webSocket/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "rxjs/webSocket",
"typings": "./index.d.ts",
"main": "./index.js",
"module": "../_esm5/webSocket/index.js",
"es2015": "../_esm2015/webSocket/index.js",
"sideEffects": false
}
8 changes: 0 additions & 8 deletions src/websocket/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig/compat/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"rxjs/testing": ["../src/testing/index"],
"rxjs/ajax": ["../src/ajax/index"],
"rxjs/operators": ["../src/operators/index"],
"rxjs/websocket": ["../src/websocket/index"]
"rxjs/webSocket": ["../src/webSocket/index"]
}
},
"include": [
Expand Down
Loading

0 comments on commit d5658fe

Please sign in to comment.