-
Notifications
You must be signed in to change notification settings - Fork 642
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
production build seems to shrink asynchronous actions name (middleware) #492
Comments
It is probably not related to mst itself but the uglifier that minimizes
the function name of your flow. How is login declared?
…On vr 27 okt. 2017 18:42 Fabien JUIF ***@***.***> wrote:
[image: image]
<https://user-images.githubusercontent.com/17828231/32114837-e296908a-bb44-11e7-8804-6575b978765c.png>
*version:* 1.1.0 / 1.0.0
I have an action named login, at start I can catch it (type action) :
{
fullname: "/auth/login",
name:"login",
path:"/auth",
}
At the end I can't catch it (type flow_return) :
{
fullpath: "/auth/t",
name: "t",
path: "/auth",
}
I saw this bug using trampss-on-action.
But I wanted to try with a simpler middleware to see if the error comes
from me :
addMiddleware(store, (call, next) => {
const { type, name } = call
console.log('bug ?', { type, name })
next(call)
})
And it seems that this is the build version of mobx-state-tree :(
[image: image]
<https://user-images.githubusercontent.com/17828231/32115285-81085cf2-bb46-11e7-92b7-575b789d5739.png>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#492>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhG3Fp3C8_YCAu85cB3Ti4O_LJXXBks5swgffgaJpZM4QJUnq>
.
|
export default types
.model({
user: types.maybe(User),
})
.actions(self => ({
setUser: (user) => {
localStorage.setItem('user', JSON.stringify(user))
self.user = user
},
}))
.actions(self => ({
init: () => {
const raw = localStorage.getItem('user')
if (raw) self.setUser(JSON.parse(raw))
},
login: process(function* login(auth) {
// query
const query = gql`
query {
user (email: "${auth.email}", password: "${auth.password}") {
id
token
}
}
`
const { data: { user } } = yield client.query({ query, fetchPolicy: 'network-only' })
// update store and localstorage
if (user) self.setUser(user)
}),
logout: () => {
localStorage.removeItem('user')
self.user = null
},
}))
.views(self => ({
get token() { return self.user && self.user.token },
get logged() { return !!self.token },
})) I thank about the uglifier, but then how the type |
Ok https://github.com/mobxjs/mobx-state-tree/blob/master/packages/mobx-state-tree/src/core/flow.ts#L43 The name for asynchronous actions is not the field name declared into mobx-state-tree login: flow(function* /* this is it -> */ login(auth) { } So this is why uglifier shrink it :( |
Wild idea, what if we declared asynchronous action this way ? const Store = types
.model({})
.actions(self => ({
login: function* login() { /* ... */ },
}) And then Then into flow implementation we can add a parameter, the name (which is the field from the object returned by the export function flow(name: string, asyncAction: any): any {
return createFlowSpawner(name, asyncAction)
} Advantages :
Drawbacks:
edit: edit2: warning added to trampss-mst-onaction |
Something like this: https://github.com/fabienjuif/mobx-state-tree/pull/1/files I have to test it, I am really not sure about this. |
We had something like that, the problem is that unfortunatelly if generator gets transpiled the check we used wont work :/ |
That's just what i try here @mattiamanzati I think : https://github.com/fabienjuif/mobx-state-tree/pull/2/files edit: as I come to the transpiled conclusion :( https://github.com/fabienjuif/mobx-state-tree/pull/1/files#r148020321 edit2:
|
btw, from top of my head you can use `flow("name", function *() {})` to
preserve name, and otherwise maybe we should add that?
Op di 31 okt. 2017 om 16:07 schreef Fabien JUIF <notifications@github.com>:
… That's just what i try here @mattiamanzati
<https://github.com/mattiamanzati> I think :
https://github.com/fabienjuif/mobx-state-tree/pull/2/files
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#492 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhH9HVkuxjMyxwBaW-Zz7JyzF7h8Jks5sxzfHgaJpZM4QJUnq>
.
|
@mweststrate I prefer not to specify name 3 times (action field, into flow parameter, and as a named function) I think with this start of solution it could work: https://github.com/fabienjuif/mobx-state-tree/pull/2/files I will read #456 as @mattiamanzati suggests |
@fabienjuif I'll write some pseudocode tomorrow, or maybe even an implementation :) |
I agree :) (although there is no reason anymore to name the function, but
still)
Op di 31 okt. 2017 om 16:11 schreef Fabien JUIF <notifications@github.com>:
… @mweststrate <https://github.com/mweststrate> I prefer not to specify
name 3 times (action field, into flow parameter, and as a named function)
I think with this start of solution it could work:
https://github.com/fabienjuif/mobx-state-tree/pull/2/files
I will read #456 <#456>
as @mattiamanzati <https://github.com/mattiamanzati> suggest
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#492 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhHN6bVjRuL4yVAUG7_jqMwfIS6Z-ks5sxzi8gaJpZM4QJUnq>
.
|
👍
Op di 31 okt. 2017 om 16:13 schreef Michel Weststrate <mweststrate@gmail.com
…:
I agree :) (although there is no reason anymore to name the function, but
still)
Op di 31 okt. 2017 om 16:11 schreef Fabien JUIF ***@***.***
>:
> @mweststrate <https://github.com/mweststrate> I prefer not to specify
> name 3 times (action field, into flow parameter, and as a named function)
>
> I think with this start of solution it could work:
> https://github.com/fabienjuif/mobx-state-tree/pull/2/files
>
> I will read #456 <#456>
> as @mattiamanzati <https://github.com/mattiamanzati> suggest
>
> —
> You are receiving this because you were mentioned.
>
>
> Reply to this email directly, view it on GitHub
> <#492 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABvGhHN6bVjRuL4yVAUG7_jqMwfIS6Z-ks5sxzi8gaJpZM4QJUnq>
> .
>
|
@mattiamanzati It will be great if you look at my second PR linked above and tell me what's wrong with this idea (so I can understand 😊) |
https://github.com/fabienjuif/mobx-state-tree/pull/2/files#diff-060ef979aa0afd5ee7c8fe9cbd2b69edR43
|
@fabienjuif #456 (comment) replace "action" with flow, and you'll basically get the gist :) |
Ok I understand it now :) Thank you ! |
Ideally I would love a "createDecorator(fn)" api that returns a new function, and copy the metadata from the previous fn (like we do with $mst_middlewares) |
We could decorate the function returned by But your snippet still not works with this idea: .actions(self => {
const internalSave= flow(function*(){
})
return ({
save: flow(function*(){
// do stuff...
yield internalSave()
})
})
} How do I'm getting confused. |
In that case internalSave wont emit any middleware event, as it is not an exported function :) |
Interested in this one also - in preserving async action names in uglified builds. Would it be an appropriate use of MST to implement logic that depends on whether certain actions have been invoked, just by capturing action names via For example, knowing whether a particular async action had ever been invoked successfully (or is currently running) can enable the presentation layer to either show a loading message or display any existing data already in the store. I think my net question is whether preserving the names of async actions is a design goal for MST and whether building logic based on Thanks, and thanks for creating this awesome library! |
@hmedney this is all about the lib I created here and this is why I dig this issue :) |
Hi @fabienjuif ah, nice - like the global function approach. I was going down a different path of capturing all the async actions in a MST tree and then observing changes in the tree. @mweststrate @mattiamanzati It's somewhat implicit in this issue, but I was wondering if you could confirm before I go too much further down this road - is basing logic on async action events via |
Closing this issue as it is inactive for quite a while. Best open new issues for new questions. |
version: 1.1.0 / 1.0.0
I have an action named
login
, at start I can catch it (typeaction
) :At the end I can't catch it (type
flow_return
) :I saw this bug using trampss-mst-onaction.
But I wanted to try with a simpler middleware to see if the error comes from me :
And it seems that this is the build version of mobx-state-tree :(
The text was updated successfully, but these errors were encountered: