Questions tagged [mixins]

A mixin is a way to enhance an object with properties or methods from another object without inheriting from that object.

Mixins are related to inheritance in that an object receives properties or methods from another object but are typically not limited in number. They are often used as a way to "tack on" behavior to objects rather then to say that objects are related to each other.

For example, we may have an Album class. Since an album has multiple tracks, we may want to enumerate through it; however, it is also very similar to our Single class. In our design, we may then inherit from Single, but also choose to mix in Enumerable, a mixin that defines mechanisms for enumerating an object.

2137 questions
22
votes
3 answers

Vue/Nuxt: How to define a global method accessible to all components?

I just want to be able to call {{ globalThing(0) }} in templates, without needing to define globalThing in each .vue file. I've tried all manner of plugin configurations (or mixins? not sure if Nuxt uses that terminology.), all to no avail. It…
Marc
  • 1,812
  • 4
  • 23
  • 36
22
votes
4 answers

Django Rest Framework - "detail": "Not found."

Hi when doing this request: groups/25010a31-fc5b-47c8-9c5c-d740e5743f52/members/4/ - I get "detail": "Not found" However, if you look in the queryset I have printed the Groupmember instance and this ends up printing out that particular instance so…
Danny
  • 889
  • 3
  • 10
  • 19
21
votes
3 answers

Are there scala-like mixins for C++?

Scala Mixins
Łukasz Lew
  • 48,526
  • 41
  • 139
  • 208
21
votes
2 answers

Should mixins use parent attributes?

I'm working on a python project where I need to use about 20 different classes implementing a list of functionalities such as : "download", "parse", "update", etc. Several functionalities can easily be factorized by using a superclass since the…
Jbb
  • 483
  • 3
  • 15
21
votes
2 answers

Is it possible to include module per object in ruby?

Is it possible to include module per instance in ruby? i.e. in Scala, you can do the following. val obj = new MyClass with MyTrait can you do something similar in ruby, maybe something similar to following? obj = Object.new include MyModule
Yeonho
  • 3,629
  • 4
  • 39
  • 61
21
votes
8 answers

java traits or mixins pattern?

Is there a way to emulate mixins or traits in java? basically, I need a way to do multiple inheritance so I can add common business logic to several classes
joshjdevl
  • 7,092
  • 12
  • 45
  • 57
20
votes
3 answers

Sass mixin for background transparency back to IE8

I'm new to Sass and struggling with this. I can't get the color to render in both hex (for IE) and rgba. Every little piece is frustrating me because I haven't mastered the syntax yet, and Google results for Sass are still sparse. Here's the…
RSG
  • 7,013
  • 6
  • 36
  • 51
20
votes
6 answers

Sass compiler throws 'undefined mixin' error when mixins are kept in seperate folder

Here is the screenshot of my website structure. In my mixins file, I have created all the necessary sass mixins. I have created this mixin for border radius: @mixin border-radius($radius) { -webkit-border-radius: $radius; …
Arindam Dawn
  • 1,769
  • 2
  • 18
  • 35
20
votes
3 answers

Mixin common fields between serializers in Django Rest Framework

I have this: class GenericCharacterFieldMixin(): attributes = serializers.SerializerMethodField('character_attribute') skills = serializers.SerializerMethodField('character_skill') def character_attribute(self, obj): …
AncientSwordRage
  • 7,086
  • 19
  • 90
  • 173
20
votes
3 answers

How to define a dynamic mixin or function name in SASS?

I want to dynamically create mixins in SASS, named after each item in the list, but it doesn't seem to work. I tried this but I get an error: $event-icons: fair, concert, art-show, conference, dance-show, film, party, festival, theatre,…
Cristian
  • 5,877
  • 6
  • 46
  • 55
19
votes
5 answers

"The Ruby way" (mixins and class reopening) vs. dependency injection

In studying mixins vs. dependency injection, I often hear the phrase "the Ruby way." Often developers say something along the lines of Ruby lets you reopen classes and redefine methods means that you can easily "inject" new references into your…
Chad Johnson
  • 21,215
  • 34
  • 109
  • 207
19
votes
3 answers

How to call super method when overriding a method through a trait

It would appear that it is possible to change the implementation of a method on a class with a trait such as follows: trait Abstract { self: Result => override def userRepr = "abstract" } abstract class Result { def userRepr: String =…
jedesah
  • 2,983
  • 2
  • 17
  • 29
19
votes
3 answers

Setting variable to @mixin in Sass?

Is there way to set @include mixin(); to variable? I tried this @mixin bg-gradient($fallback, $type, $positionX, $positionY, $from, $from-percent, $to, $to-percent){ background: $fallback; background: -webkit-#{$type}-gradient($positionX…
FoxKllD
  • 971
  • 3
  • 13
  • 22
18
votes
2 answers

CSS-Less class extend class with pseudo class

I was wondering how I could do something like the following with less css: .btn { color : black; } .btn:hover { color : white; } .btn-foo { .btn; &:hover { .btn:hover; } } Of-course this is just an example, what need to point is if…
panosru
  • 2,709
  • 4
  • 33
  • 39
18
votes
1 answer

The class 'PreferredSizeWidget' can't be used as a mixin because it's neither a mixin class nor a mixin

After upgrading to Flutter 3.10 (and Dart 3), I am getting this error: The class 'PreferredSizeWidget' can't be used as a mixin because it's neither a mixin class nor a mixin. The current version of the code: class MyAppBar extends StatelessWidget…
Hossein Yousefpour
  • 3,827
  • 3
  • 23
  • 35