项目原始demo,不改动
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。
 
 
 
 

56 行
1.4 KiB

  1. function inserted(el, binding) {
  2. const modifiers = binding.modifiers ||
  3. /* istanbul ignore next */
  4. {};
  5. const value = binding.value;
  6. const isObject = typeof value === 'object';
  7. const callback = isObject ? value.handler : value;
  8. const {
  9. once,
  10. ...modifierKeys
  11. } = modifiers;
  12. const hasModifiers = Object.keys(modifierKeys).length > 0;
  13. const hasOptions = isObject && value.options; // Options take top priority
  14. const options = hasOptions ? value.options : hasModifiers // If we have modifiers, use only those provided
  15. ? {
  16. attributes: modifierKeys.attr,
  17. childList: modifierKeys.child,
  18. subtree: modifierKeys.sub,
  19. characterData: modifierKeys.char // Defaults to everything on
  20. } : {
  21. attributes: true,
  22. childList: true,
  23. subtree: true,
  24. characterData: true
  25. };
  26. const observer = new MutationObserver((mutationsList, observer) => {
  27. /* istanbul ignore if */
  28. if (!el._mutate) return; // Just in case, should never fire
  29. callback(mutationsList, observer); // If has the once modifier, unbind
  30. once && unbind(el);
  31. });
  32. observer.observe(el, options);
  33. el._mutate = {
  34. observer
  35. };
  36. }
  37. function unbind(el) {
  38. /* istanbul ignore if */
  39. if (!el._mutate) return;
  40. el._mutate.observer.disconnect();
  41. delete el._mutate;
  42. }
  43. export const Mutate = {
  44. inserted,
  45. unbind
  46. };
  47. export default Mutate;
  48. //# sourceMappingURL=index.js.map