Coder Social home page Coder Social logo

spyfu-vuex-helpers's People

Contributors

achiandet avatar scottbedard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spyfu-vuex-helpers's Issues

Possible api improvements

Finding the instance in each mutation / getter can be a bit redundant, leaving this here as a potential solution.

// mutations
export default {
    
    // current
    foo: findInstanceThen((instance, payload) => {
        // ...
    }),
	
    // possible new api
    ...instanceMutations({
        foo(instance, payload) {
            // ...
        },
    }),
}

// getters
export default {
    
    // current
    foo: state => id => {
        const instance = findInstance(state, id) {
          
        // ...
    },
        
    // possible new api
    ...instanceGetters({
        foo(instance) {
            // ...
        },
    }),
};

mapInstanceMutations

When simpleInstanceSetters mutations are mapped with vuex mapMutations, vm's id property is ignored and the mapped mutations expects { id, value } type payload.

It would be very helpful to add a mapInstanceMutations helper.

Add warnings in development

The findInstanceThen helper should throw a couple warnings in development

  • When the state does not contain an instances array
  • When the payload does not contain an id property
  • When the target instance was not found

Add config parameter

The findInstanceThen helper should accept a config object to modify the instance array name and id property. We should be able to make a custom version of the helper by partially applying the configuration.

import helpers from 'spyfu-vuex-helpers';

const findInstanceThen = helpers.findInstanceThen.bind(null, {
    stateKey: 'instances', 
    instanceKey: 'id',
});

The above is a bit clunky, but it gets the idea across. We should come up with a cleaner api for customizing the helper.

Improve error messaging for mapTwoWayState

While working, it's easy to forget that mapTwoWayState does not share the same API as Vuex's mapState function. The following should throw a more descriptive error.

export default {
    computed: {
        ...mapTwoWayState('someNamespace', [
            'whatever',
        ]),
    },
};

Currently, no error is thrown by our helper, and Vue will be unable to access the desired state. This warning will be logged, but it doesn't really help describe why the error is happening.

[Vue warn]: Property or method "whatever" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

Partial configuration causes error

Applying partial configuration to findInstanceThen causes an error.

Steps to reproduce

  • Use the helper with only stateKey or instanceKey defined

Expected result

  • The undefined key should use the default value

Actual result

  • An error is thrown because the config object is used as a whole, leaving one of the keys undefined

Importing helpers broke in 0.5.0 or 0.5.1

Leaving this here as a reminder to myself to look into it. Something about 0.5.0 or 0.5.1 broke the ability to import helpers. This is possibly caused by the addition of a peer dependency, we need to look into it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.