WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Legion Beta archived threads (https://www.wowinterface.com/forums/forumdisplay.php?f=177)
-   -   What is mixin? (https://www.wowinterface.com/forums/showthread.php?t=53415)

galvin 05-08-16 10:36 AM

What is mixin?
 
I see this in blizzard code. Also see it in the xml, what does it do?

SDPhantom 05-08-16 11:06 AM

It takes a given table and copies the contents into the frame's table. This started showing up in WoD code.

p3lim 05-08-16 11:13 AM

Think of it as inheriting from a template.

SDPhantom 05-08-16 12:08 PM

Kind of, only the "templates" are other Lua tables in which the entries are copied from.

MunkDev 05-08-16 05:04 PM

The name comes from functions being "mixed in" with the widget's table. It's basically just dynamic inheritance from an independent source. If your frame is a meal you're preparing, then mixin functions/tables can be seen as spices. They exist independently from the meal itself, but can be added to your meal, in which case it'll be part of said meal.

SDPhantom 05-08-16 06:36 PM

I think the OP would get it by now. All these analogies are making my head hurt.

Fizzlemizz 05-08-16 06:51 PM

And not one coctail in sight :eek:

galvin 05-09-16 01:51 AM

Thanks for answers :)

myrroddin 05-09-16 10:49 AM

I haven't had time to snoop. Where are Blizzard's mixins?

Fizzlemizz 05-09-16 12:26 PM

See Blizzard_GarrisonMissionUI.xml line 1910 which points to Blizzard_GarrisonMissionUI.lua lines 14 and 16.

SDPhantom 05-09-16 12:38 PM

In WoD, they're mostly used in the Blizzard LoD addons. In XML, this is a tag on a UI object called MixIn as highlighted below.
Code:

<Frame name="GarrisonMissionFrame" inherits="GarrisonMissionFrameTemplate, GarrisonUITemplate" mixin="GarrisonMission,GarrisonFollowerMission">
Note: GarrisonMission in Blizzard_GarrisonMissionTemplates.lua line 5, GarrisonFollowerMission is in Blizzard_GarrisonMissionUI.lua line 14.



In Legion, there's a Lua-implemented function that Blizzard uses as well.
Lua Code:
  1. -- where ... are the mixins to mixin
  2. function Mixin(object, ...)
  3.     for i = 1, select("#", ...) do
  4.         local mixin = select(i, ...);
  5.         for k, v in pairs(mixin) do
  6.             object[k] = v;
  7.         end
  8.     end
  9.  
  10.     return object;
  11. end
  12.  
  13. -- where ... are the mixins to mixin
  14. function CreateFromMixins(...)
  15.     return Mixin({}, ...)
  16. end

Resike 05-09-16 02:24 PM

It's basically a table deep copy, to create skeleton objects for future use.


All times are GMT -6. The time now is 02:04 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI