zebraClass is a createClass extensions that uses its lazy-loading functionality to provide an easy-to-use interface for shared inheritances. Requires createClass.
zebraClass is a createClass extensions that uses the lazy-loading functionality to provide an easy-to-use interface for shared inheritance. Requires createClass.
If you are developing an application that has different versions of the same class for different usages but you want the same inheritance chain for both classes you're going to need this if you don't want to uglify your code by creating single files for each class and loading your classes in a zebra way.
Let's assume you're developing an application that allows you to edit and solve puzzles. You're going to create one controller for the Game and one for the Editor. Sounds quite simple- and it is. You're going to create the base class "Controller" and then derive your classes "GameController" and "EditorController" from that class. But let's assume you're going to create different controllers for different kinds of puzzles. So you've got a BaseController and derive both a CrosswordController and a SudokuController from these. Now things got a bit more tricky. One option would be to place the Game and Editor controllers on top of the concrete game controller like this: BaseController -> CrosswordController -> [Game/Editor]CrosswordController
But as soon as things get a bit trickier and you need to hook your concrete controllers inbetween those controllers (chances increase by abstracting your game logic, e.g. BaseController -> FieldController -> GridController -> CrosswordController), you'll need a zebra kind of inheritance:
SharedBaseController -> GameBaseController -> SharedCrosswordController -> GameCrosswordController
// Tell zebraClass how to handle the game controller variations// This will automatically create the class MyPuzzleApp.GameController.// Even though it is generally possible, you should not add anything to it// But instead use the classes// MyPuzzleApp.ControllerBase and MyPuzzleApp.ControllerGamezebraClass;;;zebraClass;
;MyPuzzleAppControllerBaseprototype... // Add your shared code here...;...;...;...
;MyPuzzleAppControllerGameprototype... // Add your game code here...;...;...;...
Let's assume we've got the same controllers as above but we'd like to have both the game and the editor available. If we'd be using classic single-chain inheritance, we would not get any farer than the base controller class, since once we have added a game or an editor class, the next layer's base class wouldn't know whether to take the *Editor or the *Game class. Thus we're going to create two base-versions for both the *Editor and *Game classes (automatically handled by zebraClass): index.js:
// Tell zebraClass how to handle the game controller variationzebraClass;;;zebraClass;// Tell zebraClass how to handle the editor controller variationzebraClass;;;zebraClass;
Let's assume we've got the same controllers that we already used for multichain inheritance. But what we want to do now is adding modular functionality to the classes. Since we like it complicated we're not going to add the modular functionality at the end of the chain, but again for every single class within the inheritance chain: index.js:
// Tell zebraClass how to handle the game controller variationzebraClass;;;// Since my-module doesn't add functionality to all classes,// we have to let zebraClass take care of it.// If you don't know whether or not a module is going to// extend all classes, play it save and call this function.zebraClass;;zebraClass;...
// We're going to overwrite FieldController and GridController:;;