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

a minor complaint #8

Open
ghost opened this issue Oct 2, 2015 · 1 comment
Open

a minor complaint #8

ghost opened this issue Oct 2, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 2, 2015

I've been bothered (conceptually, not yet in reality) by an API concern in possum. stampit provides a powerful and convenient strategy to hide your internal variables and methods from the outside world via the .init() block. When possum offers a .states() block, wherein some handlers might invoke functions defined in the .methods() block...

model = possum().config({
    initialState: 'uninit'
})
.methods({
    someFunc: function () {
    }
})
.states({
    'uninit': {
        init: function (args) {
            this.someFunc()
        }
    }
}).create()

model.someFunc() // valid, though it probably isn't intended to be

... implementers are forced (by default) to expose their internal api. A possum is powerful because it exposes a consistent api via .handle()- which becomes quickly muddied as soon as you use a .methods() block.

Not a huge complain, but it would be neat to have external consumers of a possum be limited literally to possumInstance.handle() and possumInstance.currentState.

@mnichols
Copy link
Owner

mnichols commented Oct 2, 2015

I think I understand your concerns. My initial thought is that you dont have to put everything onto possum directly. You can information hide either by using the state facility I added, or you can use proper modules which are intended for this sort of thing:

//mymodule.js

function myFunc(){}
export default possum().config({
    initialState: 'uninit'
})
.states({
    'uninit': {
        init: function (args) {
            someFunc()
        }
    }
}).create()

OR

//mymodule.js

var myHiddenThingy = {
    myFunc: function() {}
};
export default possum().config({
    initialState: 'uninit'
})
.states({
    'uninit': {
        init: function (args, target) {
            target.someFunc()
        }
    }
})
.target(myHiddenThingy)
.create()

That said, I will consider exposing access to the states collection so you can manipulate it in the init call. I am not sure I like this yet because I really want to keep possum single concerned and let app developer work out their problems of information hiding, etc.

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

1 participant