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

map only one row - mapRowFields #88

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

guilemos
Copy link
Contributor

Support to map only one row that lives at a array/object when we are out of a loop.

This is useful when working with "active row".

const state = {
  byId: {
    "/rooms/1": {
        name: "Nice room"
    },
    "/rooms/2": {
        name: "Nice room 2"
    },
  },
  allIds: ["/rooms/1", "/rooms/2"],
};
...mapRowFields('rooms', { item: 'byId[/rooms/2]' }),
<template>
    <v-input v-model="item.name" />
</template>

However, I am stuck with the best way to use it. For this PR be worth, we should be able to make row parameter dynamic.

...mapRowFields('rooms', { item: 'byId[/rooms/2]' }), //<-- '/rooms/2' must be dynamic

Reading the docs, I think same happens here: 'addresses[0].town',

export default {
  computed: {
    // When using nested data structures, the string
    // after the last dot (e.g. `firstName`) is used
    // for defining the name of the computed property.
    ...mapFields([
      'user.firstName',
      'user.lastName',
      // It's also possible to access
      // nested properties in arrays.
      'addresses[0].town',
    ]),
  },
};

I think this is a limitation related with vuex#863
Maybe I can make this PR better using a 'active property' approach, like:

const state = {
  byId: {
    "/rooms/1": {
        name: "Nice room"
    },
    "/rooms/2": {
        name: "Nice room 2",
        vuexMapFieldsActiveRow: true
    },
  },
  allIds: ["/rooms/1", "/rooms/2"],
};
...mapRowFields('rooms', { item: 'byId' }),
<template>
    <v-input v-model="item.name" /> //<-- Two-wat enabled for row '/rooms/2' 
</template>

Any ideas?

Best regards

@coveralls
Copy link

coveralls commented Feb 23, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling 570b5d9 on guilemos:feature/mapRow into ae30a03 on maoberlehner:master.

@guilemos
Copy link
Contributor Author

I think this PR solves #43

@guilemos
Copy link
Contributor Author

guilemos commented May 8, 2020

Hello @maoberlehner, could you take a look at this? Thank you

@guilemos
Copy link
Contributor Author

guilemos commented May 8, 2020

I did move forward with this PR in my project and solve the 'dynamic parameter' like this:

  data() {
    return {
      itemId: this.$route.params.room ? decodeURIComponent(this.$route.params.room) : uuid(),
    };
  },
 ...mapRowFields('rooms', { item: (c) => { return `byId[${c.itemId}]`; } }),

@maoberlehner
Copy link
Owner

Hey @guilemos thanks for contributing!

There are a couple of things that need to be fixed before I can consider to merge this PR:

  • It looks like you changed permissions on a couple (all?) files. In the "Files changed" tab are a lot of files listed with no changes. Please fix that.
  • You unnecessarily removed whitespace here and here.
  • Please install and use ESLint and fix all the linting errors.
  • Please update the README with information how and when to use this. Most importantly focus on what's the difference to mapMultiRowFields() and when to use one over the other.

Thanks!

@guilemos
Copy link
Contributor Author

Hi @maoberlehner,

Once mapRowFields feature is much more similar to mapFields than mapMultiRowFields, I wondering if make more sense add two features to mapFields function:

  1. Ability to map all properties when path return a object, e.g.: users[0];
  2. Ability to mapFields to accept functions as path to make feature above dynamic.

So I did submit PR #95 which implements the solution above. I'll keep PR #88 so you can decide which one is a best solution.

In short, PR #88 creates a new function semantically similar to mapFields once target is "map fields" of only one "row" inside a array, just like current mapFields function does inside "store". #95 add 2 new abilities to the mapFields function so we can avoid 2 functions with same semantic.

Thank you!

@guilemos
Copy link
Contributor Author

I’ll update the docs after you decide.

Regards

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

Successfully merging this pull request may close these issues.

3 participants