Skip to content

Commit

Permalink
Merge pull request #1661 from Automattic/fix/missing-domain-events
Browse files Browse the repository at this point in the history
DNS: more consistent and realistic handling of DNS events
  • Loading branch information
Igor Klimer committed Dec 16, 2015
2 parents 5514065 + 6742f49 commit 9dffb14
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
13 changes: 4 additions & 9 deletions client/lib/domains/dns/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,11 @@ function reducer( state, payload ) {
const { action } = payload;

switch ( action.type ) {
case ActionTypes.DNS_DELETE:
if ( ! action.error ) {
state = deleteDns( state, action.domainName, action.record );
}
break;

case ActionTypes.DNS_ADD_COMPLETED:
if ( ! action.error ) {
state = addDns( state, action.domainName, action.record );
}
state = addDns( state, action.domainName, action.record );
break;
case ActionTypes.DNS_DELETE_COMPLETED:
state = deleteDns( state, action.domainName, action.record );
break;
case ActionTypes.DNS_FETCH:
if ( ! state[ action.domainName ] ) {
Expand Down
6 changes: 3 additions & 3 deletions client/lib/domains/dns/test/reducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe( 'Domains: DNS reducer', () => {
},
payload = {
action: {
type: ActionTypes.DNS_DELETE,
type: ActionTypes.DNS_DELETE_COMPLETED,
domainName: DOMAIN_NAME,
record: RECORD_TXT
}
Expand All @@ -39,7 +39,7 @@ describe( 'Domains: DNS reducer', () => {
},
payload = {
action: {
type: ActionTypes.DNS_DELETE,
type: ActionTypes.DNS_DELETE_COMPLETED,
domainName: DOMAIN_NAME,
record: RECORD_TXT
}
Expand All @@ -59,7 +59,7 @@ describe( 'Domains: DNS reducer', () => {
},
payload = {
action: {
type: ActionTypes.DNS_DELETE,
type: ActionTypes.DNS_DELETE_COMPLETED,
domainName: DOMAIN_NAME,
record: RECORD_TXT_WITHOUT_ID
}
Expand Down
29 changes: 17 additions & 12 deletions client/lib/upgrades/actions/domain-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,30 @@ function fetchDns( domainName ) {

function addDns( domainName, record, onComplete ) {
wpcom.addDns( domainName, record, ( error ) => {
Dispatcher.handleServerAction( {
type: ActionTypes.DNS_ADD_COMPLETED,
domainName,
record,
error
} );
if ( ! error ) {
Dispatcher.handleServerAction( {
type: ActionTypes.DNS_ADD_COMPLETED,
domainName,
record,
} );
}

onComplete( error );
} );
}

function deleteDns( domainName, record, onComplete ) {
Dispatcher.handleViewAction( {
type: ActionTypes.DNS_DELETE,
domainName,
record
} );
wpcom.deleteDns( domainName, record, ( error ) => {
if ( ! error ) {
Dispatcher.handleServerAction( {
type: ActionTypes.DNS_DELETE_COMPLETED,
domainName,
record,
} );
}

wpcom.deleteDns( domainName, record, onComplete );
onComplete( error );
} );
}

function fetchNameservers( domainName ) {
Expand Down
2 changes: 1 addition & 1 deletion client/lib/upgrades/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports.action = keyMirror( {
CART_PRIVACY_PROTECTION_ADD: null,
CART_PRIVACY_PROTECTION_REMOVE: null,
DNS_ADD_COMPLETED: null,
DNS_DELETE: null,
DNS_DELETE_COMPLETED: null,
DNS_FETCH: null,
DNS_FETCH_COMPLETED: null,
DOMAIN_LOCKING_ENABLE_COMPLETED: null,
Expand Down

0 comments on commit 9dffb14

Please sign in to comment.