E
E
Eugene2015-07-13 14:34:45
ActionScript
Eugene, 2015-07-13 14:34:45

Is it possible to create a mediator in RoboticLegs without binding to a view?

Good day.
In the enterprise, they decided to start a project on RL2 and actually such a question. Is it possible to create a mediator without linking to a clip?
Specific example: I have several planets, buildings \ characters "live" on each of the planets ...
At each moment of time I need to display only one planet on the screen, the rest of the time I do not need clips for all characters on all planets. But at the same time, I need them to exist inside the context, to catch messages.
In my home project, I applied the following structure:

// Любой объект на поверхности планеты.
interface IPlanetActor {
    function register();
}

// например персонаж, который бегает по планете
// По всем признакам он является медиатором: В него инжектятся модели и сигналы,
// в момент регистрации он подписывается на сигналы и начинает взаимодействовать с окружением,
// до тех пор пока не "решит удалиться", вызвав kill().
class Character implements IPlanetActor {
    [inject] // какие-то зависимости
    
    // рассылается при добавлении\удалении в мир
    [inject] public var signalCharacterAdded: SignalCharacterAdded;
    [inject] public var signalCharacterRemoved: SignalCharacterRemoved;
    
    // ловит что бы удалиться вместе с планетой
    [inject] public var signalPlanetRemoved: SignalPlanetRemoved;

    public function register() {
        // Подписываемся на сигналы
        signalCharacterAdded.dispatch(this);
    }

    protected function kill() { //вызывется по желанию самого персонажа или при получении SignalPlanetRemoved
        // удаляем подписи на сигналы
        signalCharacterRemoved.dispatch(this);
    }
}

class Planet {
    [inject] public var injector: Injector; 

    // рассылает при уничтожении планеты
    [inject] public var signalPlanetRemoved: SignalPlanetRemoved; 

    [inject] public var signalCharacterAdded: SignalCharacterAdded;
    [inject] public var signalCharacterRemoved: SignalCharacterRemoved;
    
    private var charactersList: Vector.<Character>; // < заполняется на основании signalCharacterAdded, signalCharacterRemoved

    public function registerPlanetActor(actor: IPlanetActor): void {
        injector.injectInto(actor);
        actor.register();
    }
}

At the time of choosing the planet, I already create a surface view, request a list of characters, based on them, CharacterView + CharacterMeadiator are created, which repeat everything for Character.
But I'm not sure that this approach is correct from the point of view of Rl2. For a home project, this suits me completely, but is it worth dragging this into production?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question