Is it OK to have variables in a Lightning Component Helper

Someone from the Aura team might chime in with a more definitive answer; however, I think that helper variables are acceptable in certain situations. You have to be careful though as helpers are singletons.

In your example above, this works so long as you only have 1 FormDraggableElement.cmp. Suppose you had two completely separate drag and drop instances, they would both share the helper so you could potentially see some weird side effects from shared variables getting mixed up. This is a problem as old as javascript and there are a lot of solutions (name spacing, etc) available to work around that.

Drag and drop is a bit of one-off because users probably won't be dragging and dropping 2 different things simultaneously. Any components sharing the helper variables there will just take turns using them. In a perfect world, lightning would prefer you to cmp.set('v.draggedComponent', draggedCmp); In my experience though, it's often not worth the overhead and complexity of sending the components into the valueProvider blackhole - what with locker service and all. I'd probably just put a namespace id on the component and have the helper store keep track of different components in a map on the helper.

TLDR; When choosing where to persist data in lightning. Determine if ALL the instance of that component on the page need the same data - Helper is OK. Else use component.set()


Don't store data in the helper. While it's not explicitly forbidden, the documentation does not specify that it is safe to store data in the helper, so you should make no assumptions that it is until/unless the documentation states that this is an appropriate use of the helper. Personally, I'd expect that they'll probably lock this down eventually. Typically, you'll want at least two components; one for the dropzone and one for the draggable elements. I wrote a gist that does this without the extra layer of components, but this is how I'd recommend you go about doing it. If you need cross-DropZone functionality, you'll want to store that data in a parent component so that all DropZone components can communicate with each other.