From 0c335b6693fbbbad09e1ad7bd2c0ab163abfe2ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Goyet?= Date: Mon, 19 Jun 2017 09:46:08 +0200 Subject: [PATCH] dispatch events in javascript workflow --- dest/javascript/alerts.js | 21 ++++++++++++++++++--- dest/javascript/alerts.js.map | 2 +- dest/javascript/alerts.min.js | 2 +- src/javascript/alerts.js | 19 +++++++++++++++++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/dest/javascript/alerts.js b/dest/javascript/alerts.js index 8a59b57..f1d363d 100644 --- a/dest/javascript/alerts.js +++ b/dest/javascript/alerts.js @@ -107,14 +107,29 @@ var TrowelAlert = function () { this.element = element; this.timesCollection = [].slice.call(this.element.querySelectorAll('[data-alert="times"]')); - return this.listener(); + + this.events = this.events(); + this.listener(); + this.element.dispatchEvent(this.events.mounted); + return; } _createClass(TrowelAlert, [{ + key: 'events', + value: function events() { + var mounted = new Event('trowel.alert.mounted'); + var remove = new Event('trowel.alert.remove'); + var removed = new Event('trowel.alert.removed'); + + return { mounted: mounted, remove: remove, removed: removed }; + } + }, { key: 'removeAlert', value: function removeAlert() { - return this.element.remove(); - console.log('remove alert', this.element); + this.element.dispatchEvent(this.events.remove); + this.element.remove(); + this.element.dispatchEvent(this.events.removed); + return; } }, { key: 'listener', diff --git a/dest/javascript/alerts.js.map b/dest/javascript/alerts.js.map index 98a7632..7b16c17 100644 --- a/dest/javascript/alerts.js.map +++ b/dest/javascript/alerts.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap dbc9d4342a2ef5c4c1c0","webpack:///./src/javascript/alerts.js"],"names":["TrowelAlerts","elements","forEach","element","index","element_obj","TrowelAlert","timesCollection","slice","call","querySelectorAll","listener","remove","console","log","map","times","addEventListener","removeAlert","bind"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA,mDAA2C,cAAc;;AAEzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;;;;;;;;;;;;;;;;;;IChEqBA,Y,GACnB,sBAAYC,QAAZ,EAAsB;AAAA;;AACpBA,WAASC,OAAT,CAAiB,UAASC,OAAT,EAAkBC,KAAlB,EAAyB;AACxC,QAAIC,cAAc,IAAIC,WAAJ,CAAgBH,OAAhB,CAAlB;AACD,GAFD;AAGD,C;;kBALkBH,Y;;IAQfM,W;AACJ,uBAAYH,OAAZ,EAAqB;AAAA;;AACnB,SAAKA,OAAL,GAAeA,OAAf;AACA,SAAKI,eAAL,GAAuB,GAAGC,KAAH,CAASC,IAAT,CAAc,KAAKN,OAAL,CAAaO,gBAAb,CAA8B,sBAA9B,CAAd,CAAvB;AACA,WAAO,KAAKC,QAAL,EAAP;AACD;;;;kCAEa;AACZ,aAAO,KAAKR,OAAL,CAAaS,MAAb,EAAP;AACAC,cAAQC,GAAR,CAAY,cAAZ,EAA4B,KAAKX,OAAjC;AACD;;;+BAEU;AAAA;;AACT,aAAO,KAAKI,eAAL,CAAqBQ,GAArB,CAAyB;AAAA,eAASC,MAAMC,gBAAN,CAAuB,OAAvB,EAAgC,MAAKC,WAAL,CAAiBC,IAAjB,OAAhC,CAAT;AAAA,OAAzB,CAAP;AACD","file":"alerts.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"TrowelAlerts\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"TrowelAlerts\"] = factory();\n\telse\n\t\troot[\"TrowelAlerts\"] = factory();\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap dbc9d4342a2ef5c4c1c0","export default class TrowelAlerts {\n constructor(elements) {\n elements.forEach(function(element, index) {\n let element_obj = new TrowelAlert(element);\n })\n }\n}\n\nclass TrowelAlert {\n constructor(element) {\n this.element = element;\n this.timesCollection = [].slice.call(this.element.querySelectorAll('[data-alert=\"times\"]'));\n return this.listener();\n }\n\n removeAlert() {\n return this.element.remove();\n console.log('remove alert', this.element);\n }\n\n listener() {\n return this.timesCollection.map(times => times.addEventListener('click', this.removeAlert.bind(this)));\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/javascript/alerts.js"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 2d18665e951f2055a557","webpack:///./src/javascript/alerts.js"],"names":["TrowelAlerts","elements","forEach","element","index","element_obj","TrowelAlert","timesCollection","slice","call","querySelectorAll","events","listener","dispatchEvent","mounted","Event","remove","removed","map","times","addEventListener","removeAlert","bind"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA,mDAA2C,cAAc;;AAEzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;;;;;;;;;;;;;;;;;;IChEqBA,Y,GACnB,sBAAYC,QAAZ,EAAsB;AAAA;;AACpBA,WAASC,OAAT,CAAiB,UAASC,OAAT,EAAkBC,KAAlB,EAAyB;AACxC,QAAIC,cAAc,IAAIC,WAAJ,CAAgBH,OAAhB,CAAlB;AACD,GAFD;AAGD,C;;kBALkBH,Y;;IAQfM,W;AACJ,uBAAYH,OAAZ,EAAqB;AAAA;;AACnB,SAAKA,OAAL,GAAeA,OAAf;AACA,SAAKI,eAAL,GAAuB,GAAGC,KAAH,CAASC,IAAT,CAAc,KAAKN,OAAL,CAAaO,gBAAb,CAA8B,sBAA9B,CAAd,CAAvB;;AAEA,SAAKC,MAAL,GAAc,KAAKA,MAAL,EAAd;AACA,SAAKC,QAAL;AACA,SAAKT,OAAL,CAAaU,aAAb,CAA2B,KAAKF,MAAL,CAAYG,OAAvC;AACA;AACD;;;;6BAEQ;AACP,UAAMA,UAAU,IAAIC,KAAJ,CAAU,sBAAV,CAAhB;AACA,UAAMC,SAAS,IAAID,KAAJ,CAAU,qBAAV,CAAf;AACA,UAAME,UAAU,IAAIF,KAAJ,CAAU,sBAAV,CAAhB;;AAEA,aAAO,EAAED,gBAAF,EAAWE,cAAX,EAAmBC,gBAAnB,EAAP;AACD;;;kCAEa;AACZ,WAAKd,OAAL,CAAaU,aAAb,CAA2B,KAAKF,MAAL,CAAYK,MAAvC;AACA,WAAKb,OAAL,CAAaa,MAAb;AACA,WAAKb,OAAL,CAAaU,aAAb,CAA2B,KAAKF,MAAL,CAAYM,OAAvC;AACA;AACD;;;+BAEU;AAAA;;AACT,aAAO,KAAKV,eAAL,CACJW,GADI,CACA;AAAA,eAASC,MAAMC,gBAAN,CAAuB,OAAvB,EAAgC,MAAKC,WAAL,CAAiBC,IAAjB,OAAhC,CAAT;AAAA,OADA,CAAP;AAED","file":"alerts.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"TrowelAlerts\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"TrowelAlerts\"] = factory();\n\telse\n\t\troot[\"TrowelAlerts\"] = factory();\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 2d18665e951f2055a557","export default class TrowelAlerts {\n constructor(elements) {\n elements.forEach(function(element, index) {\n let element_obj = new TrowelAlert(element);\n })\n }\n}\n\nclass TrowelAlert {\n constructor(element) {\n this.element = element;\n this.timesCollection = [].slice.call(this.element.querySelectorAll('[data-alert=\"times\"]'));\n\n this.events = this.events();\n this.listener();\n this.element.dispatchEvent(this.events.mounted);\n return;\n }\n\n events() {\n const mounted = new Event('trowel.alert.mounted');\n const remove = new Event('trowel.alert.remove');\n const removed = new Event('trowel.alert.removed');\n\n return { mounted, remove, removed };\n }\n\n removeAlert() {\n this.element.dispatchEvent(this.events.remove);\n this.element.remove();\n this.element.dispatchEvent(this.events.removed);\n return;\n }\n\n listener() {\n return this.timesCollection\n .map(times => times.addEventListener('click', this.removeAlert.bind(this)));\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/javascript/alerts.js"],"sourceRoot":""} \ No newline at end of file diff --git a/dest/javascript/alerts.min.js b/dest/javascript/alerts.min.js index 4a7e0c0..127febb 100644 --- a/dest/javascript/alerts.min.js +++ b/dest/javascript/alerts.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("TrowelAlerts",[],t):"object"==typeof exports?exports.TrowelAlerts=t():e.TrowelAlerts=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n