question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@mixin and @mixes support

See original GitHub issue

First off, well done on v2. It is looking like a huge step forward from v1. 👏

I saw that @mixin is supported but are there plans to support @mixes as well.

I noticed from the source that @mixin is handled like an interface; would it be better if @mixin was handled like a type-def instead? This could make the handling of @mixes easier.

For example, the following code:

/**
 * @mixin A
 * @property {string} one
 * @property {string} two
 */

...

/**
 * @typedef {Object} B
 * @mixes A
 * @property {string} three
 */

… would produce the following types:

declare type A = {
    one: string;
    two: string;
}

declare type B = A & {
    three: string;
}

Interfaces, and class extensions could still be handled by @interface and @extends

If you are yet to think about or work on this, and you agree with using types for @mixin/@mixes, I will start putting together a PR.

Let me know what you think? ❤️

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
englercjcommented, Jan 9, 2019

Hey @marcandrews, happy new year!

Have you had a chance to take a look at this?

0reactions
magicmatatjahucommented, Sep 13, 2020

@englercj Hello! Firstly: great job with the library! Probably this issue will be good place to my problem in https://github.com/asyncapi/parser-js/pull/118 PR. If you had time to understand the problem and suggest solution, if I’m doing something wrong, or maybe the library has a bug in my case, I’d appreciate it.

So… I have a definition for mixins like:

/**
 * Implements functions to deal with the Tags object.
 * @mixin
 */
const MixinTags = { some methods... }

and then I use those mixins to extend class like:

/**
 * Implements functions to deal with a ChannelParameter object.
 * @class
 * @alias module:@asyncapi/parser#ChannelParameter
 * @extends Base
 * @mixes MixinDescription
 * @mixes MixinSpecificationExtensions
 * @returns {ChannelParameter}
 */
class ChannelParameter extends Base {...}

As you can see I want to have ChannelParameter class inside the @asyncapi/parser module and also types for methods extended from mixins MixinDescription and MixinSpecificationExtensions. Everything works as expected, but (I don’t know) mixins have generated declare namespace {MixinsName} with methods definition and declare interface {MixinsName} without any content, something like:

declare namespace MixinTags {
   tags(): Tag[];
}

declare interface MixinTags {
}

And here is a problem, because Tag is a model inside the @asyncapi/parser module and it’s not visible by namespace. I tried making something like:

/**
 * Implements functions to deal with the Tags object.
 * @alias module:@asyncapi/parser#MixinTags
 */
const MixinTags = { some methods... }

to generate types for mixins inside the @asyncapi/parser, but then I haven’t types for methods from mixins inside the type of mixes class… Any advice how to handle generation mixins inside the module and also generation of methods from mixins iinside the extended classes? I created the small script to remove generated namespaces outside the module @asyncapi/parser, but I don’t like this solution. Thanks for the help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sass: @mixin and @include
Mixins allow you to define styles that can be re-used throughout your stylesheet. ... Once Sass added support for hyphens to match CSS's...
Read more >
Mixin - Wikipedia
Some languages do not support mixins on the language level, but can easily mimic them by copying methods from one object to another...
Read more >
Mixins - The Modern JavaScript Tutorial
The simplest way to implement a mixin in JavaScript is to make an object with useful methods, so that we can easily merge...
Read more >
Support mixes and mixin #59 - eslint/doctrine - GitHub
Part of #5.
Read more >
What is a mixin and why is it useful? - Stack Overflow
The point of a mixin is to create a type that can be "mixed in" to any other type via inheritance without affecting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found