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

Custom struct infrastructure #176

Open
koraa opened this issue Apr 15, 2021 · 1 comment
Open

Custom struct infrastructure #176

koraa opened this issue Apr 15, 2021 · 1 comment
Labels
enhancement New feature or request needs-api-design

Comments

@koraa
Copy link
Contributor

koraa commented Apr 15, 2021

Js structs have a number of disadvantages:

  • methods are unbound
  • new construction
  • This behaves weirdly.
  • No explicit handling of

We could substitute our own syntax:

// Foo extends Bar
const Foo = struct('Foo', Bar, {
  // property; must be set during initialization
  'foo': undefined,
  // property with default value (supplied using deep clone)
  'foo': 42,
  // property, with value generated by calling the function
  'foo': Prop.init((self) => undefined),
  // property; with getter/setter
  'foo': Prop({
    get: (self) =>,
    set: (self) =>,
  }),
  // property; 
  // property, assigned by calling the provided function
  // Bound method syntax
  'foo': (self) => 
  // Static bound method/property/etc
  '@foo': (cls) => 
});

Only hard rule is: @ is for static, no @ is instance.
Provide some trait intoProp or something that contains normalization rules for properties that turn everything into a Property({ init(), get(), set() }). The normalization rule for undefined is to throw (to enforce explicit initialization). The normalization rule for Functions is binding on initialization and hiding from enumerable properties and so on.

By default .init(foo, bar, baz) and .namedInit({ foo, bar, baz }) is provided.

Highly flexible; metaprogrammable; supports reflection.

@koraa koraa added the enhancement New feature or request label Apr 15, 2021
@koraa
Copy link
Contributor Author

koraa commented Apr 30, 2021

Also provide tuple as a special case of/wrapper around struct. Tuple works like struct but assumes property declarations are in order (cannot use object literal) and implements object destructuring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-api-design
Projects
None yet
Development

No branches or pull requests

1 participant