Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

feat: base polycon code #5

Merged
merged 35 commits into from
Aug 4, 2022
Merged

feat: base polycon code #5

merged 35 commits into from
Aug 4, 2022

Conversation

Chriscbr
Copy link
Contributor

@Chriscbr Chriscbr commented Jul 25, 2022

Setting up an initial version of the polycons API. Based on several iterations of the RFC, Mark's POC, my spinoff of Mark's POC, the team's code from our last hackathon, and many team members' feedback.

TODO:

  • Add contributing guide future
  • Add authoring guide

@Chriscbr Chriscbr changed the title feat: unit test polycon and polycon factory feat: base polycon code Jul 25, 2022
@Chriscbr Chriscbr requested review from noyfactor and yammesicka July 25, 2022 18:24
Copy link

@yammesicka yammesicka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome! 🦄

src/polycon.ts Outdated Show resolved Hide resolved
src/process.ts Outdated Show resolved Hide resolved
test/polycon.test.ts Show resolved Hide resolved
test/polycon.test.ts Outdated Show resolved Hide resolved
test/polycon.test.ts Outdated Show resolved Hide resolved
API.md Outdated Show resolved Hide resolved
API.md Outdated Show resolved Hide resolved
@noyfactor
Copy link

@Chriscbr this is great work. I feel like there are some gaps in the readme, and maybe a poc in the SDK repo could help highlight the APIs and their usage?

@Chriscbr Chriscbr requested review from noyfactor and yammesicka July 26, 2022 16:56
Chriscbr and others added 3 commits July 27, 2022 18:40
- Make sure `Polycon` extends `Construct` to ensure that languages that use nominal typing (such as Java, .NET, etc) will accept a polycon everywhere constructs are accepted (add a test).
- Refactor the constructor path and use a marker on the scope to distinguish between polycon construction and the construction of the concrete type.
- Add a few tests to verify some assumptions.
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some random notes

src/polycon.ts Outdated Show resolved Hide resolved
src/process.ts Outdated Show resolved Hide resolved
test/polycon.test.ts Show resolved Hide resolved
Chriscbr and others added 4 commits July 29, 2022 10:30
This is a proposal based on [this comment](https://github.com/monadahq/polycons/pull/15/files#r933560022). 

The basic idea is that both the polycon class (e.g. `Dog`) and the concrete class (`Poodle`) extend a common abstract base type (e.g. `DogBase`).

This has the following effects:

1. No need to protect against stack overflow (the concrete class doesn't actually extend the polycon).
2. It is now possible to instantiate any concrete type directly (added a test that instantiates a `Labrador` even if when `Dog` resolves to `Poodle`.
3. We can still share common implementation at the base.
4. Enforce that concrete classes actually implement all abstract methods and properties (previously this was only by convention).

The polycon constructor has a quirky pattern:

```ts
constructor(scope, id, props) {
  super(null as any, id, props);
  return Polycons.create(QUALIFIER, scope, id, props);
}
```

The call to `super()` with `null` as the `scope` does two things:
1. The base construct is not attached to our tree.
2. The `null` can be used by the base class to bail out early:

```ts
class DogBase {
  public readonly foo: number;

  constructor(scope, id, props) {
    super(scope, id);
  
    if (!scope) {
      // initialize all readonly props with dummy values, this obj is thrown away
      this.foo = -1;
      return;
    }

    this.foo = 7947; // <-- the real thing
  }
}
```
src/polycon-factory.ts Outdated Show resolved Hide resolved
src/polycon-factory.ts Show resolved Hide resolved
@Chriscbr Chriscbr requested a review from eladb August 1, 2022 21:39
README.md Outdated Show resolved Hide resolved
@Chriscbr Chriscbr requested a review from eladb August 4, 2022 16:27
eladb
eladb previously approved these changes Aug 4, 2022
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is ready to publish. Just a few minor comments left.
Conditionally approved.

README.md Outdated Show resolved Hide resolved
docs/index.md Outdated Show resolved Hide resolved
docs/index.md Outdated Show resolved Hide resolved
docs/index.md Outdated Show resolved Hide resolved
docs/index.md Outdated Show resolved Hide resolved
docs/index.md Outdated Show resolved Hide resolved
docs/index.md Show resolved Hide resolved
src/polycon-factory.ts Outdated Show resolved Hide resolved
@eladb
Copy link
Contributor

eladb commented Aug 4, 2022

(added do-not-merge)

@@ -0,0 +1 @@
TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbonig can you help with this?

@eladb eladb removed the do-not-merge label Aug 4, 2022
@mergify mergify bot merged commit b0b8c92 into main Aug 4, 2022
@mergify mergify bot deleted the rybickic/base branch August 4, 2022 22:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants