Skip to content

Commit

Permalink
expose use node context (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
mresposito authored Apr 3, 2020
1 parent 1687460 commit 894b4b0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ export * from "./hooks";
export * from "./interfaces";
export * from "./nodes";
export * from "./render";

// We expose this methods for candu's internal usage. Use at your own risksi
export { useInternalEditor } from "./editor/useInternalEditor";
1 change: 1 addition & 0 deletions packages/core/src/nodes/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./Canvas";
export * from "./useNodeContext";
6 changes: 4 additions & 2 deletions packages/core/src/nodes/useInternalNode.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useContext, useMemo } from "react";
import { NodeContext, NodeProvider } from "./NodeContext";
import { NodeProvider } from "./NodeContext";
import { Node } from "../interfaces";
import { useInternalEditor } from "../editor/useInternalEditor";

import { useNodeContext } from "./useNodeContext";

type internalActions = NodeProvider & {
inNodeContext: boolean;
actions: {
Expand All @@ -20,7 +22,7 @@ export function useInternalNode<S = null>(
export function useInternalNode<S = null>(
collect?: (node: Node) => S
): useInternalNode<S> {
const context = useContext(NodeContext);
const context = useNodeContext();
const { id, related, connectors } = context;

const { actions: EditorActions, query, ...collected } = useInternalEditor(
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/nodes/useNodeContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { useContext } from "react";

import { NodeContext } from "./NodeContext";

export const useNodeContext = () => useContext(NodeContext);

0 comments on commit 894b4b0

Please sign in to comment.