mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-09-23 10:21:11 +00:00
Merge "Create the settings reducer" into mpga
This commit is contained in:
commit
cacd6ee04c
|
@ -1,4 +1,4 @@
|
||||||
( function ( mw, $ ) {
|
( function ( mw ) {
|
||||||
|
|
||||||
// Sugar for the mw.popups.reducers.eventLogging reducer.
|
// Sugar for the mw.popups.reducers.eventLogging reducer.
|
||||||
var counts = mw.popups.counts;
|
var counts = mw.popups.counts;
|
||||||
|
@ -235,61 +235,30 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reducer for actions that modify the state of the view
|
* Reducer for actions that modify the state of the settings
|
||||||
*
|
*
|
||||||
* @param {Object} state before action
|
* @param {Object} state
|
||||||
* @param {Object} action Redux action that modified state.
|
* @param {Object} action
|
||||||
* Must have `type` property.
|
|
||||||
* @return {Object} state after action
|
* @return {Object} state after action
|
||||||
*/
|
*/
|
||||||
mw.popups.reducers.renderer = function ( state, action ) {
|
mw.popups.reducers.settings = function ( state, action ) {
|
||||||
if ( state === undefined ) {
|
if ( state === undefined ) {
|
||||||
state = {
|
state = {
|
||||||
isAnimating: false,
|
shouldShow: false
|
||||||
isInteractive: false,
|
|
||||||
showSettings: false
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( action.type ) {
|
switch ( action.type ) {
|
||||||
case mw.popups.actionTypes.PREVIEW_ANIMATING:
|
case mw.popups.actionTypes.SETTINGS_SHOW:
|
||||||
return $.extend( {}, state, {
|
return nextState( state, {
|
||||||
isAnimating: true,
|
shouldShow: true
|
||||||
isInteractive: false,
|
|
||||||
showSettings: false
|
|
||||||
} );
|
} );
|
||||||
case mw.popups.actionTypes.PREVIEW_INTERACTIVE:
|
case mw.popups.actionTypes.SETTINGS_HIDE:
|
||||||
return $.extend( OO.copy( state ), {
|
return nextState( state, {
|
||||||
isAnimating: false,
|
shouldShow: false
|
||||||
isInteractive: true,
|
|
||||||
showSettings: false
|
|
||||||
} );
|
|
||||||
case mw.popups.actionTypes.PREVIEW_CLICK:
|
|
||||||
return $.extend( OO.copy( state ), {
|
|
||||||
isAnimating: false,
|
|
||||||
isInteractive: false,
|
|
||||||
showSettings: false
|
|
||||||
} );
|
|
||||||
case mw.popups.actionTypes.COG_CLICK:
|
|
||||||
return $.extend( OO.copy( state ), {
|
|
||||||
isAnimating: true,
|
|
||||||
isInteractive: false,
|
|
||||||
showSettings: true
|
|
||||||
} );
|
|
||||||
case mw.popups.actionTypes.SETTINGS_DIALOG_INTERACTIVE:
|
|
||||||
return $.extend( OO.copy( state ), {
|
|
||||||
isAnimating: false,
|
|
||||||
isInteractive: true,
|
|
||||||
showSettings: true
|
|
||||||
} );
|
|
||||||
case mw.popups.actionTypes.SETTINGS_DIALOG_CLOSED:
|
|
||||||
return $.extend( OO.copy( state ), {
|
|
||||||
isAnimating: false,
|
|
||||||
isInteractive: false,
|
|
||||||
showSettings: false
|
|
||||||
} );
|
} );
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}( mediaWiki, jQuery ) );
|
}( mediaWiki ) );
|
||||||
|
|
|
@ -27,10 +27,8 @@
|
||||||
event: undefined,
|
event: undefined,
|
||||||
interaction: undefined
|
interaction: undefined
|
||||||
},
|
},
|
||||||
renderer: {
|
settings: {
|
||||||
isAnimating: false,
|
shouldShow: false
|
||||||
isInteractive: false,
|
|
||||||
showSettings: false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'It should initialize the state by default'
|
'It should initialize the state by default'
|
||||||
|
@ -179,17 +177,27 @@
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( '#renderer', function ( assert ) {
|
QUnit.test( '#settings: SETTINGS_SHOW', function ( assert ) {
|
||||||
assert.expect( 1 );
|
assert.expect( 1 );
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
mw.popups.reducers.renderer( {}, { type: 'PREVIEW_ANIMATING' } ),
|
mw.popups.reducers.settings( {}, { type: 'SETTINGS_SHOW' } ),
|
||||||
{
|
{
|
||||||
isAnimating: true,
|
shouldShow: true
|
||||||
isInteractive: false,
|
|
||||||
showSettings: false
|
|
||||||
},
|
},
|
||||||
'It should set isAnimating to true on the PREVIEW_ANIMATING action'
|
'It should mark the settings dialog as ready to be shown'
|
||||||
|
);
|
||||||
|
} );
|
||||||
|
|
||||||
|
QUnit.test( '#settings: SETTINGS_HIDE', function ( assert ) {
|
||||||
|
assert.expect( 1 );
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
mw.popups.reducers.settings( {}, { type: 'SETTINGS_HIDE' } ),
|
||||||
|
{
|
||||||
|
shouldShow: false
|
||||||
|
},
|
||||||
|
'It should mark the settings dialog as ready to be closed'
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue