Skip to content
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

Changes to accessing Custom Data #2812

Closed
yulin-dong opened this issue Jun 16, 2016 · 7 comments
Closed

Changes to accessing Custom Data #2812

yulin-dong opened this issue Jun 16, 2016 · 7 comments

Comments

@yulin-dong
Copy link

yulin-dong commented Jun 16, 2016

I have recently updated ui-route from ver 0.2.15 to 0.3.1 and I noticed that accessing to custom data has been changed. With ver 0.2.15, I could use _.extend(newVar, $state.current.data) to initiate newVar using lodash. However, in ver 0.3.1, the properties of $state.current.data are in$state.current.data.__proto__. With this change, I have to do _.extend(newVar, $state.current.data.__proto__) to achieve the same result. Is this intended behavior?

Thanks,

@eddiemonge
Copy link
Contributor

can you give a plnkr example?

@yulin-dong
Copy link
Author

yulin-dong commented Jun 17, 2016

While trying to create an example in plnkr, it turned out that the plnkr worked fine with just including the ui-router and angular. Then I debugged my code again, and noticed that in the debugger that $state.current.data was shown as 'extend', not Object (see screen shot below).
screen shot 2016-06-17 at 5 02 25 pm

Maybe something is wrong with my code, or some libraries are incompatible with ui-router. I will continue debugging my code. If you someone has seen similar problem and could provide some hints, it will be greatly appreciated.

@yulin-dong
Copy link
Author

yulin-dong commented Jun 17, 2016

Ok, I figured out the cause.

I have a state A.B.C which is abstract, with which I have the custom data associated. Also I have a controller for state A.B.C. Then I define non-abstract states such as A.B.C.1, A.B.C.2 etc. When A.B.C.1 is shown, it uses the controller associated with state A.B.C. The changes from ver 0.2.15 to 0.3.1 seems having changed the way how the inherited custom data is packed. Instead of being an object, it is now an 'extend', which is created by the following code

        // inherit 'data' from parent and override by own values (if any)
        data: function(state) {
          if (state.parent && state.parent.data) {
            state.data = state.self.data = inherit(state.parent.data, state.data);
          }
          return state.data;
        },

So to get around of this problem, I can do _.extend(this, $state.$current.parent.data); and in some places, I have to do _.extend(this, $state.$current.parent.parent.data); which is not pretty at all.

However, I still question whether this is the intended behavior.

@paol
Copy link

paol commented Jun 22, 2016

FYI, this is related to bug #2631

@yulin-dong
Copy link
Author

Indeed. Thanks @paol

@eddiemonge
Copy link
Contributor

Closing as a duplicate since it seems duplicated, not just related

@motin
Copy link

motin commented Feb 8, 2017

So to get around of this problem, I can do _.extend(this, $state.$current.parent.data); and in some places, I have to do _.extend(this, $state.$current.parent.parent.data); which is not pretty at all.

A prettier way to get the old behavior back is found at #3045 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants