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

feat(typescript): Basic TypeScript support #59

Merged
merged 15 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"dist/index.js": {
"bundled": 24023,
"minified": 11383,
"gzipped": 4170,
"bundled": 24014,
"minified": 11375,
"gzipped": 4166,
"treeshaked": {
"rollup": {
"code": 9441,
"import_statements": 578
"code": 9428,
"import_statements": 565
},
"webpack": {
"code": 11003
Expand All @@ -16,6 +16,6 @@
"dist/index.cjs.js": {
"bundled": 27112,
"minified": 13128,
"gzipped": 4391
"gzipped": 4390
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"homepage": "https://github.com/drcmda/react-three-fiber#readme",
"dependencies": {
"@babel/runtime": "^7.4.3",
"@types/three": "^0.93.30",
"lodash-es": "^4.17.11",
"pointer-events-polyfill": "^0.4.4-pre",
"react-reconciler": "^0.20.1",
Expand All @@ -75,7 +76,6 @@
"@babel/preset-typescript": "^7.3.3",
"@types/lodash-es": "^4.17.3",
"@types/react": "^16.8.12",
"@types/three": "^0.93.30",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"husky": "^1.3.1",
"lint-staged": "^8.1.5",
Expand Down
4 changes: 3 additions & 1 deletion src/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const Canvas = React.memo(
const [bind, size] = useMeasure()
const [intersects, setIntersects] = useState([])
const [raycaster] = useState(() => new THREE.Raycaster())
const [mouse] = useState(() => new THREE.Vector2())
const [mouse] = useState(() => new THREE.Vector3())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh my, what did i do there ... good catch! πŸ˜…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The promise of TypeScript is real!

const [defaultCam, setDefaultCamera] = useState(() => {
const cam = new THREE.PerspectiveCamera(75, 0, 0.1, 1000)
cam.position.z = 5
Expand Down Expand Up @@ -168,7 +168,9 @@ export const Canvas = React.memo(
const canvasRect = state.current.canvasRect
const x = ((event.clientX - canvasRect.left) / (canvasRect.right - canvasRect.left)) * 2 - 1
const y = -((event.clientY - canvasRect.top) / (canvasRect.bottom - canvasRect.top)) * 2 + 1

mouse.set(x, y, 0.5)

raycaster.setFromCamera(mouse, state.current.camera)
}, [])

Expand Down