Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@creately/lschannel-es6

Package Overview
Dependencies
Maintainers
4
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@creately/lschannel-es6 - npm Package Compare versions

Comparing version 2.0.0 to 2.0.2

LICENSE

12

dist/index.d.ts

@@ -1,2 +0,2 @@

import { Subject } from 'rxjs/Rx';
import { Subject } from 'rxjs';
export declare class Channel<T> extends Subject<T> {

@@ -6,6 +6,12 @@ key: string;

static create<T>(key: string): Channel<T>;
private static randomId;
private prefix;
private counter;
private constructor();
close(): void;
next(data: T): void;
private emit(data);
private randomId();
private init;
private handler;
private emit;
private nextId;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Rx_1 = require("rxjs/Rx");
const Rx_2 = require("rxjs/Rx");
class Channel extends Rx_2.Subject {
const rxjs_1 = require("rxjs");
// Channel
// Channel ...
class Channel extends rxjs_1.Subject {
// constructor

@@ -10,6 +11,5 @@ constructor(key) {

this.key = key;
Rx_1.Observable.fromEvent(window, 'storage')
.filter(e => e.key === this.key)
.map(e => JSON.parse(e.newValue).data)
.subscribe(data => this.emit(data));
this.prefix = Channel.randomId(16);
this.counter = 0;
this.handler = this.handler.bind(this);
}

@@ -26,4 +26,21 @@ // create

this.instances.set(key, newChannel);
newChannel.init();
return newChannel;
}
// randomId
// randomId generates a reasonably random string id with given length.
static randomId(n) {
let id = '';
while (id.length < n) {
id += Math.random()
.toString(16)
.slice(2);
}
return id.slice(0, n);
}
// close
// close ...
close() {
window.removeEventListener('storage', this.handler);
}
// next

@@ -33,3 +50,3 @@ // next sets the value on localStorage for given key which

next(data) {
const event = { id: this.randomId(), data };
const event = { id: this.nextId(), data };
const value = JSON.stringify(event);

@@ -39,2 +56,16 @@ localStorage.setItem(this.key, value);

}
// init
// init ...
init() {
window.addEventListener('storage', this.handler);
}
// handler
// handler ...
handler(e) {
if (e.key !== this.key) {
return;
}
const event = JSON.parse(e.newValue);
this.emit(event.data);
}
// emit

@@ -45,13 +76,6 @@ // emit emits the data to all subscribers in this window/tab.

}
// randomId
// randomId creates a random string which will be used as event ids.
randomId() {
let id = '';
while (id.length < 16) {
const r = Math.random()
.toString(36)
.slice(2);
id += r.slice(0, 16 - id.length);
}
return id;
// nextId
// nextId ...
nextId() {
return this.prefix + ++this.counter;
}

@@ -58,0 +82,0 @@ }

{
"name": "@creately/lschannel-es6",
"version": "2.0.0",
"version": "2.0.2",
"description": "",

@@ -24,20 +24,19 @@ "main": "dist/index.js",

"devDependencies": {
"@types/jasmine": "^2.8.6",
"istanbul-instrumenter-loader": "^3.0.0",
"jasmine-core": "^2.9.1",
"karma": "^1.7.1",
"@types/jasmine": "^2.8.8",
"istanbul-instrumenter-loader": "^3.0.1",
"jasmine-core": "^3.2.1",
"karma": "^3.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage-istanbul-reporter": "^1.4.1",
"karma-jasmine": "^1.1.1",
"karma-webpack": "^2.0.9",
"prettier": "^1.10.2",
"karma-coverage-istanbul-reporter": "^2.0.3",
"karma-jasmine": "^1.1.2",
"karma-webpack": "^3.0.2",
"prettier": "^1.14.2",
"rimraf": "^2.6.2",
"ts-loader": "^2.3.7",
"typescript": "^2.7.1",
"webpack": "^3.10.0"
"ts-loader": "^4.5.0",
"typescript": "^3.0.3",
"webpack": "^4.17.1"
},
"dependencies": {
"rxjs": "^6.0.0",
"rxjs-compat": "^6.0.0"
"rxjs": "^6.0.0"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc