Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Investigate simplifying the TS Rug Parameter model #229

Closed
kipz opened this issue Jan 27, 2017 · 12 comments
Closed

Investigate simplifying the TS Rug Parameter model #229

kipz opened this issue Jan 27, 2017 · 12 comments
Assignees
Milestone

Comments

@kipz
Copy link
Contributor

kipz commented Jan 27, 2017

Currently all parameters to a TS rug are declared in an array on the Rug. While this works, and destructing can be used in simple cases, when there are many parameters, it quickly gets ugly when consuming the parameters in the function implementation (edit/review/populate etc).

At the very least, the duplication of parameter names should be removed if possible.

@kipz
Copy link
Contributor Author

kipz commented Jan 27, 2017

Proposal 1: Property Injection

class SimpleEditor implements ProjectEditor{
    name: string = "Simple"
    description: string = "My simple editor"
    @parameter({description: "num", pattern: "\\d+"})
    num: number = 10
    edit(project: Project){
        this.num == 10;
        project.addFile("src/from/typescript", "Anders Hjelsberg is God")
    }
}

Pros:

  • Super simple. No extra types/classes required
  • Can use super class for grouping

Cons:

  • Magic (this is why we didn't do this originally)
    • i.e. 10 might be overwritten by value supplied by user
  • Not thread safe (but hey, we can't ensure this anyway)

@kipz
Copy link
Contributor Author

kipz commented Jan 27, 2017

Proposal 2: Mapped types and a Parameters interface:

class MyParams implements Parameters {
  //name, type and default value from from definition
  @parameter({description: "Content", pattern: "$ContentPattern"})
  content: number = 10;
}

class SimpleEditor implements ProjectEditor<MyParams> {
    name: string = "Simple"
    description: string = "My simple editor"
    params: MyParams = new MyParams()
    edit(project: Project, p: RugParams<MyParams>)  {
        p.content == 2;
        project.addFile("src/from/typescript", "Anders Hjelsberg is God")
    }
}

Pros:

  • Could maybe reuse instances of editors for multiple requests/threads
  • Grouping via inheritance could be easy

Cons:

  • Has a separate class, more code etc.

@kipz
Copy link
Contributor Author

kipz commented Jan 27, 2017

Proposal 3: Status Quo:

https://github.com/atomist-rugs/travis-editors/blob/master/.atomist/editors/EnableTravisForRugArchiveTS.ts

Pros:

  • It's the status quo
  • Makes composition of parameters super easy

Cons:

  • Duplication of parameter names
  • Manual type coercion in interface
  • Need synthetic interface or verbose destructuring

@kipz
Copy link
Contributor Author

kipz commented Jan 27, 2017

Or any others?

@cdupuis
Copy link
Contributor

cdupuis commented Jan 27, 2017

@kipz, I like option 1 but worry about thread-safety.

Right now ProjectOperations are being cached in our runtimes. So I guess on execution we would need to create new instances of the JS Object, or so?

@jessitron
Copy link
Contributor

@cdupuis isn't caching instances dangerous anyway? They could mutate fields on the editor object at any time.

@jessitron
Copy link
Contributor

I like option 1 except for inheritance as a grouping mechanism. but it's fine.

@cdupuis
Copy link
Contributor

cdupuis commented Jan 27, 2017

The API in Rug and ProjectOperationArchiveReader was intended to allow that. But this came out of the DSL-only days. Maybe that assumption isn't valid any longer but re-creating the entire operations thing every time is not an option as this takes too long.

I think if we can't guarantee thread-safety, Rug needs to handle that internal by creating new instances on invocation.

@kipz
Copy link
Contributor Author

kipz commented Jan 27, 2017

@cd - I think we can do that, and as @jessitron - we should already be doing that anyway.

So rather than exporting an instance of the class, we'll just export the class itself, and create a new one for each call.

@cdupuis
Copy link
Contributor

cdupuis commented Jan 27, 2017

sounds good. yeah, that is indeed safer.

@ddgenome
Copy link
Contributor

I'd be happy with 1 or 3.

@kipz
Copy link
Contributor Author

kipz commented Jan 28, 2017

Proposal 1: property injection wins
#229 (comment)

Though we should be doing this already, we'll need to ensure that:

  • We create and reuse the ScriptEngine instance
  • Use separate bindings for each thread
  • Create a new instance of each rug for each operation (class to be export instead of instance)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants