Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

It that case the component should be connected to an store, and also, we will need to actions to open and close the modal. 

  1. The store should contain, at least,  the initial values for openModal and activeTrap states. Also, handlers to modified them to open and close the modal. A simple example:

  2. The actions to open and close the modal, only should dispatch the proper instructions to the store. Examples:
  3. At the
    Code Block
    languagejs
    themeDJango
    
    import {BaseStore} from 'fluxible/addons';
    
    class ExampleModalStore extends BaseStore{
        constructor(dispatcher) {
            super(dispatcher);
            this.openModal = false;
            this.activeTrap = false;
        }
    
        getState(){
            return {
                openModal : this.openModal,
                activeTrap : this.activeTrap
            };
        }
        dehydrate() {
            return this.getState();
        }
        rehydrate(state) {
            this.openModal = state.openModal;
    
        }
        openExampleModal(payload){
            this.openModal = true;
            this.activeTrap = true;
            this.emitChange();
    
        }
        closeExampleModal(payload){
            this.openModal = false;
            this.activeTrap = false;
            this.emitChange();
        }
    
    
    
    }
    ExampleModalStore.storeName = 'AttachSubdeckModalStore';
    ExampleModalStore.handlers = {
        'EXAMPLE_MODAL_OPEN' : 'openExampleModal',
        'EXAMPLE_MODAL_LOSE': 'closeExampleModal'
    
    };
    
    export default ExampleModalStore;



  4. The actions to open and close the modal, only should dispatch the proper instructions to the store. Examples:

    Code Block
    languagejs
    themeDJango
    export default function openAttachModal(context, payload, done) {
        console.log('action');
        context.dispatch('EXAMPLE_MODAL_OPEN', payload);
        done();
    }


    Code Block
    languagejs
    themeDJango
    export default function closeAttachModal(context, payload, done) {
        context.dispatch('EXAMPLE_MODAL_LOSE', payload);
        done();
    }



  5. At the modal component, we should connect it to the store and modify a little the way in which we manage the state:

    1. Connecting to the store:

      Code Block
      languagejs
      themeDJango



    2. Changes at the constructor:

    3. Update the state

    4. Close method shoul call the proper action:

  6. The open method called from another component should call the corresponding action