Skip to content

Commit

Permalink
0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Apr 4, 2017
1 parent d8fefa6 commit bde221f
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion view/frontend/web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,41 @@ define([
*/
initialize: function() {
this._super();
/** @type {?Object} */
var prevAddress;
quote.billingAddress.subscribe(
/**
* 2017-04-04
* newAddress is null if a customer has just unchecked
* the «My billing and shipping address are the same» checkbox,
* but does not select another address yet.
* @used-by Magento_Checkout/js/action/select-billing-address:
* quote.billingAddress(address);
* https://github.com/magento/magento2/blob/2.1.5/app/code/Magento/Checkout/view/frontend/web/js/action/select-billing-address.js#L23
* @param {?Object} newAddress
*/
function(newAddress) {
debugger;
/**
* 2017-04-04
* Note #1
* Naive newAddress !== prevAddress does not work correctly.
* @uses Magento_Customer/js/model/customer/address::getKey()
* getKey: function() {
* return this.getType() + this.customerAddressId;
* }
* https://github.com/magento/magento2/blob/2.1.5/app/code/Magento/Customer/view/frontend/web/js/model/customer/address.js#L48-L50
* It returns a string like «customer-address4».
* Note #2
* !newAddress ^ !prevAddress is for situations
* when newAddress or prevAddress is null or prevAddress is undefined:
* http://stackoverflow.com/a/4540443
*/
if (!newAddress ^ !prevAddress || newAddress.getKey() !== prevAddress.getKey()) {
prevAddress = newAddress;
if (newAddress) {
console.log(newAddress);
}
}
}
);
return this;
Expand Down

0 comments on commit bde221f

Please sign in to comment.