Skip to content

Constructor signature design review / questions #52

@LeaVerou

Description

@LeaVerou
const Foldable = new Protocol({
  name: 'Foldable',
  extends: [ .. ],
  requires: {
    foldr: Symbol('Foldable.foldr'),
  },
  staticRequires: { .. },
  provides: {
    Object.getOwnPropertyDescriptors({
      toArray() { .. 1},
      get length() { .. },
      contains(eq, e) { .. },
    }),
    staticProvides: { ... },
  });
  • Why would authors need to construct Symbol('Foldable.foldr') themselves? That seems antithetical to one of the core tenets of this feature (that you use symbols under the hood without defining them yourself) and introduces a disparity between the constructor and the declarative syntax (which A way to require different symbol fields than ProtocolName.* #48 would plug).
  • provides accepting descriptors also introduces a disparity between the constructor and the declarative syntax, and requires boilerplate in the vast majority of cases. It also seems like a footgun: since the most natural syntax is to just include the object literal, I can easily see authors doing that. We could define that the feature copies descriptors from these objects, which gives you the best of both worlds (simple things are easy, complex things are possible) but is specifying descriptors actually desirable? E.g. class members are non-enumerable by default. Would protocol-provided members need to be specified as explicitly enumerable: false to behave the same way?
  • Why is there a name field? What is it used for? Isn't const Foldable enough since everything is by reference?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions