Skip to content

Commit

Permalink
dnd module using wrong dnd-core types in BackendFactory confusion, no…
Browse files Browse the repository at this point in the history
…w allows basic test/html5 backends
  • Loading branch information
cormacrelf committed Jun 19, 2018
1 parent 4952b85 commit 48538f8
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions packages/angular-skyhook/src/dnd.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,41 @@ export function managerFactory(backendFactory: BackendFactory, zone: NgZone, con
return zone.runOutsideAngular(() => createDragDropManager(backendFactory, context));
}

/*
* Hold on, this gets a little confusing.
*
* A dnd-core Backend has lots of useful methods for registering elements and firing events.
* However, backends are not distributed this way.
* The HTML5Backend and the TestBackend, when imported { default as HTML5Backend }, are not Backends, they are
* functions: (manager: DragDropManager) => Backend.
* This is now known as a BackendFactory under dnd-core 4+ typescript annotations.
*
* However, Angular has its own conception of what a factory is for AOT. This is the 'factory'
* to which BackendFactoryInput refers below.
* Sometimes, users will want to preconfigure a backend (like TouchBackend, or MultiBackend).
* For this, they need to export a function that returns a configured BackendFactory
* and pass it in as { backendFactory: exportedFunction }.
*/

export interface BackendInput {
/** A plain backend, for example when using the HTML5Backend. */
backend: Backend;
/** A plain backend, for example when using the HTML5Backend. */
backend: BackendFactory;
}

export interface BackendFactoryInput {
/** Use this with the MultiBackend, with an
*
* ```
* export function createBackend() {
* return MultiBackend(...);
* }
* // ...
* SkyhookDndModule.forRoot({ backendFactory: createBackend })
* ```
*
* You have to do this to retain AOT compatibility.
*/
backendFactory: BackendFactory;
/** Use this with the MultiBackend, with an
*
* ```
* export function createBackend() {
* return MultiBackend(...);
* }
* // ...
* SkyhookDndModule.forRoot({ backendFactory: createBackend })
* ```
*
* You have to do this to retain AOT compatibility.
*/
backendFactory: () => BackendFactory;
}

@NgModule({
Expand Down

0 comments on commit 48538f8

Please sign in to comment.