captbaritone / raven-for-redux

A Raven middleware for Redux
295 stars 25 forks source link

User context #49

Closed odinuge closed 6 years ago

odinuge commented 6 years ago

Hi,

This adds a way to set the user context with a state transformer. Any thoughts about this? (the name of the new attr is kinda bad, i know). It would be nice to be able to set the user context in the same callback as the state, because most often it only depends on the state. Here is a simple example with https://github.com/reactjs/reselect, and a state transformed with https://github.com/paularmstrong/normalizr:

import { createSelector } from 'reselect';
export const selectCurrentUser = createSelector(
  state => state.users.byId,
  state => state.auth.id,
  (usersById, userId) => usersById[userId]
);
[...]
createRavenMiddleware(Raven, {
            userContextStateTransformer: selectCurrentUser
})

I have also added a few more tests in the second commit (now all lines are covered). If this looks good, i can write documentation so we can get it merged.

Thanks for this project! We use it in https://github.com/webkom/lego-webapp, and it works like a charm. :smile: We also use it for raven (the node version), but that version has a more limited API - eg.setDataCallback is not available.

codecov-io commented 6 years ago

Codecov Report

Merging #49 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #49   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines          21     24    +3     
  Branches        8      9    +1     
=====================================
+ Hits           21     24    +3
Impacted Files Coverage Δ
index.js 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1fd666b...d92db68. Read the comment docs.

odinuge commented 6 years ago

That was quick!

Sounds good @captbaritone; have added some initial documentation now.

captbaritone commented 6 years ago

Published in 1.2.0. Thanks for the PR!