zweifisch / kontur

a little DSL that outputs JSON schema
MIT License
78 stars 1 forks source link

custom properties? #1

Open natew opened 7 years ago

natew commented 7 years ago

Wondering, I have a use case to add .indexable as an option:

https://github.com/pubkey/rxdb/blob/10ec1d926e45485662fabd402cf1da3655183747/test/helper/schemas.js#L36

Rather than for kontur, would be nice to have some way to defining props. Not sure how best to do this, I could Proxy the class I guess and then check on compile, but would need access to compile function.

natew commented 7 years ago

Actually, this could actually be supported in Kontur very generically.

Non-fancy way, property method:

str.property('index', true)

Super-fancy way, using Proxy:

str.index(true)

// behind the scenes you can
str = new Proxy(str, { get(target, key) {
  console.log('add property', key);
  return (value) => str.property(key, value)
} })