invalidation-processor.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'underscore',
  7. 'uiElement',
  8. 'Magento_Customer/js/customer-data'
  9. ], function (_, Element, customerData) {
  10. 'use strict';
  11. return Element.extend({
  12. /**
  13. * Initialize object
  14. */
  15. initialize: function () {
  16. this._super();
  17. this.process(customerData);
  18. },
  19. /**
  20. * Process all rules in loop, each rule can invalidate some sections in customer data
  21. *
  22. * @param {Object} customerDataObject
  23. */
  24. process: function (customerDataObject) {
  25. _.each(this.invalidationRules, function (rule, ruleName) {
  26. _.each(rule, function (ruleArgs, rulePath) {
  27. require([rulePath], function (Rule) {
  28. var currentRule = new Rule(ruleArgs);
  29. if (!_.isFunction(currentRule.process)) {
  30. throw new Error('Rule ' + ruleName + ' should implement invalidationProcessor interface');
  31. }
  32. currentRule.process(customerDataObject);
  33. });
  34. });
  35. });
  36. }
  37. });
  38. });