Comments (3)
@lorefnon I agree that class factories are an elegant and easy way to implement a mixin style. Just that they miss one thing: Constructors (and respective call hierarchies).
This is the one reason why I implemented a dedicated mixin library back in the coffeescript days.
Decorators did not even exist as proposal at that time. I think that they would provide a cleaner integration, I agree.
Maybe I would give it a try and port my library to be based on decorators. I just wonder how the type system can be informed about additional supertypes introduced via a decorator. Any ideas on that?
from civet.
Hi, thanks for the feedback!
A primary goal of Civet is to stick to JS semantics as much as possible. In the case of mixins we'll probbaly converge on ESDecorators when/if it becomes a standard. Civet currently supports decorators using @@decorator
syntax (a single @
is ambiguous with class static fields and methods currently).
Thanks for sharing the code sample it looks pretty close to the direction that JS/TS is heading with decorators and I'm always happy to find inspiring ways to make syntax nicer.
I'm glad you like Civet and hope that it will make your wildest dreams come true.
from civet.
Besides decorators, a common pattern for mixins in ts is to use a function that extends an input class (Real world example).
Using this pattern in civet, the linked example (abbreviated) would look like:
UUIDentifiable := Base ->
class extends Base
id()
@_id ?= randomId()
AutoUUID := Base ->
class extends Base
uuid()
@_id ?= randomId()
class Named extends Mixin {}
class TestClass extends UUIDentifiable(AutoUUID Named) {}
which imho is not too bad
from civet.
Related Issues (20)
- Missing parens in `.-1` access in certain contexts
- Attempted pattern matching ternary HOT 1
- Finishing civetconfig
- `get #x` requires newline, not semicolon HOT 1
- coffeeDo bug
- Use `{}` instead of `;` for empty block
- `for`/`else` HOT 2
- Generator operators
- Cannot shadow operator with argument HOT 1
- Sourcemaps are off when used with @propName HOT 1
- Add source location to error nodes
- `-o dist/.js` errors if the `dist` folder doesn't already exist HOT 2
- `-version` with only one hyphen throws a ReferenceError HOT 1
- "Invalid command-line argument" error includes stack dump
- Splice assignment with loop
- Empty block following pattern in switch expression generates invalid JS
- hoistDec bug
- Pipeline placeholder ^^ or %% or `|x>` HOT 4
- Need full example setup civet on sveltekit HOT 2
- Regression in 0.7.11: No more implicit return in synchronous function that creates a Promise<void> HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from civet.