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

Don't require action keyword for actions #56

Closed
mweststrate opened this issue Mar 10, 2017 · 4 comments
Closed

Don't require action keyword for actions #56

mweststrate opened this issue Mar 10, 2017 · 4 comments

Comments

@mweststrate
Copy link
Member

  1. it's cumbersome
  2. if you want utilities that don't have action semantics (for example to have utilities that receive complex args), those can be extracted to static helper methods
  3. makes syntax a lot nicer, as one could write:
createModelFactory({
   done: false,
   toggle() {
     this.done = !this.done
   }
})
@mattiamanzati
Copy link
Contributor

@mweststrate You need to check if createFactory type inference works without action(), not sure about it! :/

@mweststrate
Copy link
Member Author

Should work, as factory functions are explicitly marked as such

@mattiamanzati
Copy link
Contributor

Not really unfortunately :/
See here: https://www.typescriptlang.org/play/index.html#src=export%20type%20IModel%20%3D%20%7B%0D%0A%20%20%20%20%24treenode%3A%20any%20%2F%2F%20Actually%20Node%2C%20but%20that%20should%20not%20be%20exposed%20to%20the%20public...%0D%0A%7D%20%26%20Object%0D%0A%0D%0Aexport%20interface%20IFactory%3CS%2C%20T%3E%20%7B%0D%0A%20%20%20%20(snapshot%3F%3A%20S%2C%20env%3F%3A%20Object)%3A%20T%20%26%20IModel%0D%0A%20%20%20%20factoryName%3A%20string%2C%0D%0A%20%20%20%20is%3A%20ITypeChecker%0D%0A%20%20%20%20isFactory%3A%20boolean%20%2F%2F%20TODO%3A%20rename%20to%20isFactory%0D%0A%20%20%20%20type%3A%20IType%0D%0A%7D%0D%0A%0D%0Aexport%20interface%20IType%20%7B%0D%0A%20%20%20%20name%3A%20string%0D%0A%20%20%20%20is(thing%3A%20IModel%20%7C%20any)%3A%20boolean%0D%0A%20%20%20%20create(snapshot%2C%20environment%3F)%3A%20any%0D%0A%20%20%20%20factory%3A%20IFactory%3Cany%2C%20any%3E%20%2F%2F%20TODO%20type%0D%0A%20%20%20%20describe()%3A%20string%0D%0A%7D%0D%0A%0D%0Aexport%20type%20ITypeChecker%20%3D%20(value%3A%20IModel%20%7C%20any)%20%3D%3E%20boolean%0D%0A%0D%0Aexport%20type%20IBaseModelDefinition%3CS%20extends%20Object%2C%20T%3E%20%3D%20%7B%5BK%20in%20keyof%20T%5D%3A%20IFactory%3Cany%2C%20T%5BK%5D%3E%20%7C%20T%5BK%5D%7D%0D%0A%0D%0Aexport%20function%20createModelFactory%3CS%20extends%20Object%2C%20T%20extends%20S%3E(baseModel%3A%20IBaseModelDefinition%3CS%2C%20T%3E)%3A%20IFactory%3CS%2C%20T%3E%0D%0Aexport%20function%20createModelFactory%3CS%20extends%20Object%2C%20T%20extends%20S%3E(name%3A%20string%2C%20baseModel%3A%20IBaseModelDefinition%3CS%2C%20T%3E)%3A%20IFactory%3CS%2C%20T%3E%0D%0Aexport%20function%20createModelFactory(arg1%2C%20arg2%3F)%20%7B%0D%0A%7D%0D%0A%0D%0Aconst%20Sample%20%3D%20createModelFactory(%7B%0D%0A%20%20%20%20hello(world%3A%20string)%20%7B%0D%0A%20%20%20%20%20%20%20%20%0D%0A%20%20%20%20%7D%0D%0A%7D)%0D%0A%0D%0Aconst%20doc%20%3D%20Sample()%0D%0Adoc.hello()

mweststrate added a commit that referenced this issue Mar 28, 2017
@mweststrate
Copy link
Member Author

Released as 0.2.0. Typings did work out luckily 😄

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

2 participants