Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

User context#49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
captbaritone merged 3 commits intocaptbaritone:masterfromodinuge:user_context
Dec 27, 2017
Merged

Conversation

@odinuge
Copy link
Contributor

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 withhttps://github.com/reactjs/reselect, and a state transformed withhttps://github.com/paularmstrong/normalizr:

import{createSelector}from'reselect';exportconstselectCurrentUser=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 inhttps://github.com/webkom/lego-webapp, and it works like a charm. 😄 We also use it forraven (the node version), but that version has a more limited API - eg.setDataCallback is not available.

@codecov-io
Copy link

codecov-io commentedDec 27, 2017
edited
Loading

Codecov Report

Merging#49 intomaster willnot change coverage.
The diff coverage is100%.

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 FilesCoverage Δ
index.js100% <100%> (ø)⬆️

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update1fd666b...d92db68. Read thecomment docs.

Copy link
Owner

@captbaritonecaptbaritone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good! Thanks for suggesting this. Add the docs and i’m happy to merge. FYI I’ll be offline until Saturday.

index.test.js Outdated
expect(context.mockTransport.mock.calls[0][0].data.user).toEqual(
userData
);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don’t think this test is really nessesary. The first one like this, in the “default config” test block is probably enough.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Removed the "duplicate" test now

index.js Outdated
breadcrumbCategory="redux-action",
filterBreadcrumbActions=filter
filterBreadcrumbActions=filter,
userContextStateTransformer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe we could call itgetUserContext? That would fit with the convention i’ve seen for naming selectors which, as you show in your example, this is.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Agree! That is a much better name!

@odinuge
Copy link
ContributorAuthor

That was quick!

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


Default:`undefined` (disabled)

Signature:`state => userContext`
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Not sure if this is the best way to do this, and still be consistent with the others. Since it cannot default tostate => undefined; because it should be possible not to use it, and use theRaven.setUserContext elsewhere....

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

How about we specify the signature as:

#### `getUserContext` _(Optional Function)_

And then omit the “default” line.

odinuge reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sounds good 👍 Fixed it now 😄

data.extra.state=stateTransformer(store.getState());
data.extra.state=stateTransformer(state);
if(getUserContext){
data.user=getUserContext(state);
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Do you think we should add a note that the original state, and not the transformed one?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You mean, a note about it overwriting any existing user context?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No, but I did indeed add a notice about that.

But, a note saying that thegetUserContext is executed with the original redux-state, andnot the state transformed via thestateTransformer.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

In the docs, as long as we refer to it as “Redux state” I think that’s clear. In the code, I think it’s self explanatory.

odinuge reacted with thumbs up emoji
README.md Outdated
Signature:`state => userContext`

The[user context] is an important part of the error reporting. When
`getUserContext` is a truthy function, the result of`getUserContext`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

All functions are truthy.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah. When setting the function tooptional, using truthy doesn't make that much sense.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe just “whengetUserContext is specified”?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍
Did a small rephrase now 😄

README.md Outdated

The[user context] is an important part of the error reporting. When
`getUserContext` is a truthy function, the result of`getUserContext`
will set the the[user context] before sending the error report.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think it’s standard to only make the first reference to a given term a link.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍

Copy link
Owner

@captbaritonecaptbaritone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good to me! I’ll cut a new release when I get back on the grid this weekend. Thanks for your quick work on this! 👏

@captbaritonecaptbaritone merged commit49f4d15 intocaptbaritone:masterDec 27, 2017
@captbaritone
Copy link
Owner

Published in 1.2.0. Thanks for the PR!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@captbaritonecaptbaritonecaptbaritone approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@odinuge@codecov-io@captbaritone

[8]ページ先頭

©2009-2025 Movatter.jp