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

Create Classes #4

Open
BigAB opened this issue Aug 14, 2019 · 0 comments
Open

Create Classes #4

BigAB opened this issue Aug 14, 2019 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@BigAB
Copy link
Owner

BigAB commented Aug 14, 2019

I actually think what I want is for a way to create a Store class/factory, that can be either invoked or new'ed to create store instances. Perhaps a createStoreClass function, or maybe something like:

class MyStore extends SimpleStore {
  static storeFn(state, actions, dependencies, resolve) {
    // store logic 
  }
}

...I think maybe I'd prefer the createStoreClass because then it could be used without new.


So then, I want a createStoreHook() function that is able to take either an instance, or Class/Factory, and maybe even just a function like createSimpleStoreHook() does now.

Because of the way it separates the shared store (from Provider) and the default context store, an instance of store needs to be able clone itself to be shared. I suppose the easiest way would be to have an instance have instance.constructor point to the class created from createStoreClass which should be use internally.


Hmm.... might need to think about this but, proposing the API right now:

createSimpleStore(storeFn) returns a store instance
SimpleStore(storeFn) returns a class/factory function
class MyStore extends Store creates a class that creates proxy based store instances**

createStoreHook( StoreClass / store / storeFn , options) creates a React hook, if a store instance is passed, the Provider will create a new store instance from store.constructor
(which feels odd but is probably the minority case anyway)

  • createStoreHook() returns a "useStore" style React hook which looks like useStore(stateSelector[, deps = []]) => [state, dispatch]

** new upcoming feature

@BigAB BigAB added the enhancement New feature or request label Aug 14, 2019
@BigAB BigAB self-assigned this Aug 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant