reload.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. var utils = require("../utils");
  3. var publicUtils = require("./public-utils");
  4. var _ = require("../lodash.custom");
  5. var defaultConfig = require("../default-config");
  6. var stream = require("./stream");
  7. /**
  8. * @param emitter
  9. * @returns {Function}
  10. */
  11. module.exports = function (emitter) {
  12. /**
  13. * Inform browsers about file changes.
  14. *
  15. * eg: reload("core.css")
  16. */
  17. function browserSyncReload(opts) {
  18. /**
  19. * BACKWARDS COMPATIBILITY:
  20. * Passing an object as the only arg to the `reload`
  21. * method with at *least* the key-value pair of {stream: true},
  22. * was only ever used for streams support - so it's safe to check
  23. * for that signature here and defer to the
  24. * dedicated `.stream()` method instead.
  25. */
  26. if (_.isObject(opts)) {
  27. if (!Array.isArray(opts) && Object.keys(opts).length) {
  28. if (opts.stream === true) {
  29. return stream(emitter)(opts);
  30. }
  31. }
  32. }
  33. /**
  34. * Handle single string paths such as
  35. * reload("core.css")
  36. */
  37. if (typeof opts === "string" && opts !== "undefined") {
  38. return publicUtils.emitChangeEvent(emitter, opts, true);
  39. }
  40. /**
  41. * Handle an array of file paths such as
  42. * reload(["core.css, "ie.css"])
  43. */
  44. if (Array.isArray(opts)) {
  45. return opts.forEach(function (filepath) {
  46. publicUtils.emitChangeEvent(emitter, filepath, true);
  47. });
  48. }
  49. /**
  50. * At this point the argument given was neither an object,
  51. * array or string so we simply perform a reload. This is to
  52. * allow the following syntax to work as expected
  53. *
  54. * reload();
  55. */
  56. return publicUtils.emitBrowserReload(emitter);
  57. }
  58. return browserSyncReload;
  59. };
  60. //# sourceMappingURL=reload.js.map