Browse Source

cleanup

main
Steve Ruiz 4 years ago
parent
commit
4a0800a5df

+ 1
- 27
packages/core/src/components/renderer/renderer.tsx View File

14
 
14
 
15
 export interface RendererProps<T extends TLShape, M extends Record<string, unknown>>
15
 export interface RendererProps<T extends TLShape, M extends Record<string, unknown>>
16
   extends Partial<TLCallbacks> {
16
   extends Partial<TLCallbacks> {
17
-  /**
18
-   * An id representing the current document. Changing the id will
19
-   * update the context and trigger a re-render.
20
-   */
21
-  id?: string
22
   /**
17
   /**
23
    * An object containing instances of your shape classes.
18
    * An object containing instances of your shape classes.
24
    */
19
    */
57
    * An object of custom options that should be passed to rendered shapes.
52
    * An object of custom options that should be passed to rendered shapes.
58
    */
53
    */
59
   meta?: M
54
   meta?: M
60
-  // Temp
61
-  onTest?: () => void
62
 }
55
 }
63
 
56
 
64
 /**
57
 /**
70
  * @returns
63
  * @returns
71
  */
64
  */
72
 export function Renderer<T extends TLShape, M extends Record<string, unknown>>({
65
 export function Renderer<T extends TLShape, M extends Record<string, unknown>>({
73
-  id,
74
   shapeUtils,
66
   shapeUtils,
75
   page,
67
   page,
76
   pageState,
68
   pageState,
90
     rPageState.current = pageState
82
     rPageState.current = pageState
91
   }, [pageState])
83
   }, [pageState])
92
 
84
 
93
-  const rId = React.useRef(id)
94
-
95
-  const [context, setContext] = React.useState<TLContextType>(() => ({
96
-    id,
85
+  const [context] = React.useState<TLContextType>(() => ({
97
     callbacks: rest,
86
     callbacks: rest,
98
     shapeUtils,
87
     shapeUtils,
99
     rScreenBounds,
88
     rScreenBounds,
100
     rPageState,
89
     rPageState,
101
   }))
90
   }))
102
 
91
 
103
-  React.useEffect(() => {
104
-    if (id !== rId.current) {
105
-      rest.onTest?.()
106
-      setContext({
107
-        id,
108
-        callbacks: rest,
109
-        shapeUtils,
110
-        rScreenBounds,
111
-        rPageState,
112
-      })
113
-
114
-      rId.current = id
115
-    }
116
-  }, [id])
117
-
118
   return (
92
   return (
119
     <TLContext.Provider value={context}>
93
     <TLContext.Provider value={context}>
120
       <Canvas
94
       <Canvas

+ 0
- 2
packages/dev/src/app.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
-import Controlled from './controlled'
3
-import Basic from './basic'
4
 import NewId from './newId'
2
 import NewId from './newId'
5
 
3
 
6
 export default function App(): JSX.Element {
4
 export default function App(): JSX.Element {

+ 1
- 14
packages/tldraw/src/components/tldraw/tldraw.tsx View File

69
   return (
69
   return (
70
     <TLDrawContext.Provider value={context}>
70
     <TLDrawContext.Provider value={context}>
71
       <IdProvider>
71
       <IdProvider>
72
-        <InnerTldraw
73
-          key={sId || 'tldraw'}
74
-          id={sId}
75
-          currentPageId={currentPageId}
76
-          document={document}
77
-        />
72
+        <InnerTldraw key={sId || 'tldraw'} currentPageId={currentPageId} document={document} />
78
       </IdProvider>
73
       </IdProvider>
79
     </TLDrawContext.Provider>
74
     </TLDrawContext.Provider>
80
   )
75
   )
81
 }
76
 }
82
 
77
 
83
 function InnerTldraw({
78
 function InnerTldraw({
84
-  id,
85
   currentPageId,
79
   currentPageId,
86
   document,
80
   document,
87
 }: {
81
 }: {
88
-  id?: string
89
   currentPageId?: string
82
   currentPageId?: string
90
   document?: TLDrawDocument
83
   document?: TLDrawDocument
91
 }) {
84
 }) {
150
     tlstate.changePage(currentPageId)
143
     tlstate.changePage(currentPageId)
151
   }, [currentPageId, tlstate])
144
   }, [currentPageId, tlstate])
152
 
145
 
153
-  React.useEffect(() => {
154
-    'Id Changed!'
155
-    console.log(id, tlstate.id)
156
-  }, [id])
157
-
158
   return (
146
   return (
159
     <Layout>
147
     <Layout>
160
       <ContextMenu>
148
       <ContextMenu>
161
         <Renderer
149
         <Renderer
162
-          id={id}
163
           page={page}
150
           page={page}
164
           pageState={pageState}
151
           pageState={pageState}
165
           shapeUtils={tldrawShapeUtils}
152
           shapeUtils={tldrawShapeUtils}

+ 0
- 4
packages/tldraw/src/components/tools-panel/tools-panel.tsx View File

32
 
32
 
33
   const isDebugMode = useSelector(isDebugModeSelector)
33
   const isDebugMode = useSelector(isDebugModeSelector)
34
 
34
 
35
-  console.log(activeTool)
36
-
37
   const selectSelectTool = React.useCallback(() => {
35
   const selectSelectTool = React.useCallback(() => {
38
-    console.log(tlstate.id)
39
     tlstate.selectTool('select')
36
     tlstate.selectTool('select')
40
   }, [tlstate])
37
   }, [tlstate])
41
 
38
 
42
   const selectDrawTool = React.useCallback(() => {
39
   const selectDrawTool = React.useCallback(() => {
43
-    console.log(tlstate.id)
44
     tlstate.selectTool(TLDrawShapeType.Draw)
40
     tlstate.selectTool(TLDrawShapeType.Draw)
45
   }, [tlstate])
41
   }, [tlstate])
46
 
42
 

+ 2
- 2
packages/tldraw/src/state/tlstate.spec.ts View File

447
   })
447
   })
448
 
448
 
449
   describe('when the document prop changes', () => {
449
   describe('when the document prop changes', () => {
450
-    it.todo('updates the document if the new id is the same as the old one')
451
-
452
     it.todo('replaces the document if the ids are different')
450
     it.todo('replaces the document if the ids are different')
451
+
452
+    it.todo('updates the document if the new id is the same as the old one')
453
   })
453
   })
454
   /*
454
   /*
455
     We want to be able to use the `document` property to update the
455
     We want to be able to use the `document` property to update the

Loading…
Cancel
Save