attach.js icon indicating copy to clipboard operation
attach.js copied to clipboard

Required attachments

Open yckart opened this issue 9 years ago • 3 comments

It would nice to have the possibility to add dependent attachments.

Sure, we could do this simply like so:

Attach.add('pluginName1', function(el) {
  var deps = el.dataset.split(' ')
  if (~deps.indexOf('pluginName2') && ~deps.indexOf('pluginName4')) {
    // stuff
  }
})

...however, makes sense to me to let this managed internally:

Attach.add('pluginName1', ['pluginName2', 'pluginName4'], function(el) {
  // stuff...
})

Update Just don't know what's the best way to go. Either check if the current node resolves all dependencies, or for the existence of those dependencies somewhere in the dom...

yckart avatar Mar 07 '16 11:03 yckart

@yckart I agree. I have been using Attach on a project recently and have often found issues with loading and instantiation where one attachment depends on another, or if one manipulates the DOM onLoad/DOMContentReady and another is skipped because it sits within it.. (don't think that makes sense, butI think this sort of interface might help.

mrmartineau avatar Mar 07 '16 13:03 mrmartineau

@mrmartineau in situations where you have several modules that depend on each other I would write another module that governs their creation and any other inter-dependent logic. I would attach this module to the parent container instead of attaching all the child modules.

For example if you had several types of filters on a page that triggered each other. You could keep those filters single purpose and create a FilterManager module to take care of the depended business logic between the filters.

nicbell avatar Mar 07 '16 15:03 nicbell

Let's assume that we want to add an editor to some sort of input field and in some cases (wysiwyg instead of markdown mode, or whatever reason) also a toolbar. This toolbar requires that the editor is attached, as the editor give's access to the current value and selection.

This might be not the best example, but would be a case where it could be helpful to have this feature available.

yckart avatar Mar 07 '16 16:03 yckart