Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add layout mutation, listeners, and custom events #558

Merged
merged 36 commits into from
Jul 7, 2022
Merged

Conversation

jalal246
Copy link
Member

@jalal246 jalal246 commented Jun 14, 2022

  • Add playgrounds to the type checking.
  • Add custom events instead of the previous approach which depended on emitting events by functions provided by each interactive element. DFlex events has $ prefix.
type DFlexEvents =
  | "$onDragOutContainer"
  | "$onDragOutThreshold"
  | "$onDragOver"
  | "$onDragLeave"
  | "$onLiftUpSiblings"
  | "$onMoveDownSiblings";

Implementation like any other event:

import type { DFlexEvents } from "@dflex/dnd";

const onDFlexEvent = (e: DFlexEvents) => {
 // Do something, or just don't.
};

// Later you can remove the listener with `removeEventListener`
document.addEventListener("$onDragLeave", onDFlexEvent);
  • Provide listeners subscription approach to provide a universal state to the interactive applications. You can subscribe anywhere in the app instead of depending on the emitted events from draggable elements. Currently, DFlex supports subscriptions to LayoutState.
interface DFlexLayoutStateEvent {
  type: "layoutState",
  layoutState: "pending" | "ready" | "dragging" | "dragEnd" | "dragCancel";
}

Implementation from anywhere inside the app:

React.useEffect(() => {
  const unsubscribe = store.listeners.subscribe((e) => {
    console.info("new layout state", e);
  }, "layoutState");

  return () => {
    unsubscribe();
  };
}, []);

@github-actions github-actions bot added the Core label Jun 16, 2022
@jalal246 jalal246 marked this pull request as ready for review June 17, 2022 18:50
@jalal246 jalal246 marked this pull request as draft June 17, 2022 19:09
@jalal246 jalal246 marked this pull request as ready for review June 20, 2022 22:07
@jalal246 jalal246 marked this pull request as draft June 20, 2022 22:26
@github-actions github-actions bot added Utils and removed Utils labels Jun 24, 2022
Refactor css to the main
Refactor lib def name
@jalal246 jalal246 changed the title Dev Add mutation, listeners, and custom events Jun 25, 2022
@jalal246 jalal246 changed the title Add mutation, listeners, and custom events Add layout mutation, listeners, and custom events Jun 25, 2022
@jalal246 jalal246 enabled auto-merge (squash) July 7, 2022 14:15
@jalal246 jalal246 merged commit 57f1804 into main Jul 7, 2022
@jalal246 jalal246 deleted the dev/wip_6_15 branch July 7, 2022 14:21
@jalal246 jalal246 removed the Test 🧪 label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant