angular / ngSocket

WebSocket support for angular
Apache License 2.0
204 stars 25 forks source link

Add possibility to filter messages with a function #19

Closed globin closed 9 years ago

globin commented 10 years ago

NGWebSocket.prototype._onMessageHandler() now take a filter property on the callback instead of pattern. This can additionally to being a string to match on exactly or a RegExp pattern be a function which will run the callback if the function evaluates to true.

Review on Reviewable

ratbeard commented 9 years ago

+1 for filtering via a function.

In my view filtering by a string/regex should be deprecated as its too app-specific. It only works if you message uses a data property, which has to be a string. For example our app uses a structure like: { messageType: 'foo', data: { rat: 1, } }. Rather than waiting for users to ask for more configuration options to support alternate message structure and needing to document them, a function is a simpler solution and works for everyone.