davestewart / vuex-pathify

Vue / Vuex plugin providing a unified path syntax to Vuex stores
https://davestewart.github.io/vuex-pathify
MIT License
1.37k stars 57 forks source link

Unable to use store.get to get nested variable with dotpath if path includes arrays #34

Closed hybridwebdev closed 5 years ago

hybridwebdev commented 6 years ago

So as the title explains, is that unless I am missing something, it's not possible to use store.get() with a dot-path like this some.nested.prop.0.apples given a structure like this: { some: { nested: { prop: [{apples: 'juicy'}] } } } I also tried some.nested.prop[0].apples which also doesn't work. However some.nested.prop will give you an array which of course contains the apples object. However, this is undesirable as this means you have to know the structure of the data ahead of time.

Hoping you can shed a light on this. Ps, I am just mind BLOWN over how amazing this project is. Keep up the great work, and thanks for such an awesome tool. It took me a while to wrap my head around how it all works, and honestly the @ decorator is a bit...err ... annoying to work around, however I read your bit about why you opted to use it which makes sense.

davestewart commented 6 years ago

Hey, hey,

Sorry for the confusion.

I decided to not support arrays on purpose, as the original intention was to support concrete properties, and I considered that the fluid nature of arrays would only add confusion:

https://davestewart.github.io/vuex-pathify/#/api/paths?id=sub-property-access

But you make a valid use case for using store.get(). I can't promise to add this in straight away, but I am persuaded to take a look at it, especially as the lib has gained some traction now and seems like it's pretty stable for everyone!

As for using . vs @, I am considering this.

I could potentially just use lodash to support universal paths, but I do need to review how the lib will determine the mutation boundary.

hybridwebdev commented 6 years ago

Well dang, I didn't expect such a quick reply. I actually came back to edit and mention I had found this: https://github.com/davestewart/vuex-pathify/issues/19 which explains why this doesn't work. I'll consider this issue closed, but it would be great to see this added. I can personally say that lodash handles the aforementioned dot path structure (including array's) just fine, as that's what I'm using as a solution now.

However, it still falls victim to the add/removal caveats that conventional vuex does. Of course there are work around's, but i'm not sure how that'd fit into your plugin.

I'll let you decide if this should remain open, as perhaps maybe others can weigh in on this.

davestewart commented 5 years ago

Array access has been added in v1.3.0