GithubHelp home page GithubHelp logo

Comments (8)

mtharrison avatar mtharrison commented on June 16, 2024

Have a look at filters. I think something like this will work:

var Confidence = require('confidence');

var config = {
    plugins: {
        '$filter': 'phase',
        '$default': { },
        '$base': {
            other: { }
        },
        local: {
            blipp: {
                showAuth: true
            }
        }
    }
}

var store = new Confidence.Store(config);

console.log(store.get('/', { phase: 'local' }));          // { plugins: { other: {}, blipp: { showAuth: true } } }
console.log(store.get('/', { phase: 'something-else' })); // { plugins: { other: {} } }

from confidence.

patrickkettner avatar patrickkettner commented on June 16, 2024

thanks, @mtharrison - that is exactly the way to do this.

lemme know if you have any question, @netei

from confidence.

netei avatar netei commented on June 16, 2024

Thanks that works well. I wasn't aware of the "$base" key, or at least didn't thought about it.

from confidence.

netei avatar netei commented on June 16, 2024

Is it possible to do the same with arrays ?

Eg

var config = {
    plugins: {
        '$filter': 'phase',
        '$default': [{"key2":"val2"}],
        '$base':  [{"key1":"val1"}],
        local:  [{"key3":"val3"}],
    }
}

and have as a result the concatenated arrays ?

from confidence.

netei avatar netei commented on June 16, 2024

It seems that it isn't possible with the current implementation to do that. Would you accept a pull request that would allow for this ?

from confidence.

patrickkettner avatar patrickkettner commented on June 16, 2024

Almost certainly, but I am not quire sure what you expect the value to be - the arrays being merged?

from confidence.

netei avatar netei commented on June 16, 2024

I would expect to get

console.log(store.get('/', { phase: 'local' }));
// [{"key1": "val1"}, {"key3", : "val3"}]

console.log(store.get('/', { phase: 'other' }));
// [{"key1": "val1"}, {"key2", : "val2"}]

from confidence.

patrickkettner avatar patrickkettner commented on June 16, 2024

yeah, PR for that would be good

from confidence.

Related Issues (20)

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.