rxjs-ws-channels-filters
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -50,2 +50,5 @@ 'use strict'; | ||
vm.channelsMatch = vm.connection.options.channelsMatch || channelsMatch; | ||
vm.filtersMatch = vm.connection.options.filtersMatch || filtersMatch; | ||
function init() { | ||
@@ -115,2 +118,6 @@ if (!vm.channels.observable) { | ||
function channelsMatch(source, target) { | ||
return source === target; | ||
} | ||
function subscribeFilter(channel, filter, responseHandle) { | ||
@@ -135,3 +142,3 @@ return initFilter(channel, filter).observable.subscribe(responseHandle); | ||
for (; i < l; i++) { | ||
if (matchFilters(channelFilters[i].filter, filter)) { | ||
if (vm.filtersMatch(channelFilters[i].filter, filter)) { | ||
return channelFilters[i]; | ||
@@ -142,3 +149,3 @@ } | ||
function matchFilters(source, target) { | ||
function filtersMatch(source, target) { | ||
if (target) { | ||
@@ -209,3 +216,3 @@ for (var p in source) { | ||
return function (data) { | ||
return data.channel === channel; | ||
return vm.channelsMatch(channel, data.channel); | ||
}; | ||
@@ -216,3 +223,3 @@ } | ||
return function (data) { | ||
return matchFilters(filter, data.filter); | ||
return vm.filtersMatch(filter, data.filter); | ||
}; | ||
@@ -238,8 +245,2 @@ } | ||
var CHANGE_TYPES = { | ||
CREATED: 1, | ||
MODIFIED: 2, | ||
DELETED: 3 | ||
}; | ||
function addDefaultOptions(userOptions) { | ||
@@ -249,2 +250,4 @@ return { | ||
invalidUrl: userOptions.invalidUrl, | ||
channelsMatch: userOptions.channelsMatch, | ||
filtersMatch: userOptions.filtersMatch, | ||
transformResponse: userOptions.transformResponse, | ||
@@ -251,0 +254,0 @@ transformRequest: userOptions.transformRequest, |
{ | ||
"name": "rxjs-ws-channels-filters", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "RxJS websockets implementation with channels and filters", | ||
"main": "dist/index.js", | ||
"dependencies": { | ||
"rxjs": "^5.3.0" | ||
"rxjs": ">=5.3.0" | ||
}, | ||
"devDependencies": { | ||
"connect": "^3.6.0", | ||
"eslint": "^3.19.0", | ||
"gulp": "^3.9.1", | ||
"gulp-clean": "^0.3.2", | ||
"gulp-useref": "^3.1.2", | ||
"http-proxy-middleware": "^0.17.4", | ||
"serve-static": "^1.12.1", | ||
"uws": "^0.14.1" | ||
"connect": "3.6.0", | ||
"eslint": "3.19.0", | ||
"gulp": "3.9.1", | ||
"gulp-clean": "0.3.2", | ||
"gulp-useref": "3.1.2", | ||
"http-proxy-middleware": "0.17.4", | ||
"serve-static": "1.12.1", | ||
"uws": "0.14.1" | ||
}, | ||
@@ -19,0 +19,0 @@ "scripts": { |
@@ -8,5 +8,9 @@ # rxjs-ws-channels-filters | ||
var options = { | ||
var options = { | ||
url: 'localhost:3000/api', | ||
invalidUrl: function (e) { | ||
// optional option if close event code is >= 1006 https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent | ||
// this function will be called expecting a promise | ||
// in the resolve of the promise the websocket connection will try again to connect with the url from the options | ||
// in the reject of the promise the websocket observer will complete | ||
return new Promise(function (resolve, reject) { | ||
@@ -20,6 +24,7 @@ setTimeout(function () { | ||
transformResponse: function (message) { | ||
// transform the response from server | ||
return message; | ||
}, | ||
transformRequest: function (message) { | ||
// transform the request sent to server | ||
if (message.filters && message.filters.length) { | ||
@@ -32,2 +37,20 @@ var i = message.filters.length - 1; | ||
return message; | ||
}, | ||
channelsMatch: function channelsMatch(source, target) { | ||
// default function to find matching channels used for sending messages to the correct channel | ||
// and to not have duplicate channels | ||
// optional option, arguments ['existing channel', 'message channel'] | ||
return source === target; | ||
}, | ||
filtersMatch: function filtersMatch(source, target) { | ||
// default function to find matching filters used for sending messages to the correct filter | ||
// and to not have duplicate filters on the same channel | ||
// optional option, arguments ['existing filter object', 'message filter object'] | ||
if (target) { | ||
for (var p in source) { | ||
if (source[p] !== target[p]) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
@@ -66,4 +89,4 @@ }; | ||
* add ability to send user messages to server on a channel and filter | ||
* add option for user custom filtering of channel and filters | ||
* make a separate repo with a server side node implementation | ||
* make better documentation | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14777
293
89
+ Addedrxjs@7.8.1(transitive)
+ Addedtslib@2.8.1(transitive)
- Removedrxjs@5.5.12(transitive)
- Removedsymbol-observable@1.0.1(transitive)
Updatedrxjs@>=5.3.0