Skip to content

Commit

Permalink
Merge pull request #151 from CrispyBacon1999/update-ntcore
Browse files Browse the repository at this point in the history
Update ntcore-ts-client to @next
  • Loading branch information
CrispyBacon1999 authored Jan 9, 2024
2 parents c14e5c4 + b9f10a7 commit 3a77b49
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 56 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"nt4",
"react"
],
"version": "1.2.0",
"version": "2.0.0",
"type": "module",
"license": "MIT",
"scripts": {
Expand All @@ -27,9 +27,10 @@
"chromatic": "chromatic --exit-zero-on-changes"
},
"dependencies": {
"ntcore-ts-client": "^0.2.1",
"ntcore-ts-client": "^2.0.0-beta.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"zod": "^3.22.4"
},
"devDependencies": {
"@storybook/addon-docs": "^7.0.13",
Expand Down Expand Up @@ -91,4 +92,4 @@
"path": "./node_modules/cz-conventional-changelog"
}
}
}
}
9 changes: 5 additions & 4 deletions src/lib/NTProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export default function NTProvider({
teamNumber,
port,
}: NTProviderProps) {
const [ntConnection, setNtConnection] =
useState<NetworkTables | null>(null);
const [ntConnection, setNtConnection] = useState<NetworkTables | null>(
null
);
const [
ntConnectionCreatedUsingTeamNumber,
setNtConnectionCreatedUsingTeamNumber,
Expand All @@ -38,11 +39,11 @@ export default function NTProvider({
// Otherwise, reconnect using the uri, or throw an error if a team number is provided
if (ntConnection === null) {
if (uri) {
setNtConnection(NetworkTables.createInstanceByURI(uri, port));
setNtConnection(NetworkTables.getInstanceByURI(uri, port));
setNtConnectionCreatedUsingTeamNumber(false);
} else if (teamNumber) {
setNtConnection(
NetworkTables.createInstanceByTeam(teamNumber, port)
NetworkTables.getInstanceByTeam(teamNumber, port)
);
setNtConnectionCreatedUsingTeamNumber(true);
oldTeamNumber.current = teamNumber;
Expand Down
10 changes: 5 additions & 5 deletions test/NTProvider.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MockedNetworkTables } from "./mocks";
test("NTProvider creates NT Instance using team number", () => {
render(<NTProvider teamNumber={123}></NTProvider>);

expect(NetworkTables.createInstanceByTeam).toHaveBeenCalledWith(
expect(NetworkTables.getInstanceByTeam).toHaveBeenCalledWith(
123,
undefined
);
Expand All @@ -24,18 +24,18 @@ test("NTProvider throws error if no uri or team number is provided", () => {

test("NTProvider uses uri if both uri and team number are provided", () => {
render(<NTProvider uri={"test"} teamNumber={123}></NTProvider>);
expect(NetworkTables.createInstanceByURI).toHaveBeenCalledWith(
expect(NetworkTables.getInstanceByURI).toHaveBeenCalledWith(
"test",
undefined
);
expect(NetworkTables.createInstanceByTeam).not.toHaveBeenCalled();
expect(NetworkTables.getInstanceByTeam).not.toHaveBeenCalled();
});

test("NTProvider successfully changes uri if it is changed after connection is created", () => {
const { rerender } = render(<NTProvider uri={"test"}></NTProvider>);
rerender(<NTProvider uri={"test2"}></NTProvider>);

expect(NetworkTables.createInstanceByURI).toHaveBeenCalledWith(
expect(NetworkTables.getInstanceByURI).toHaveBeenCalledWith(
"test",
undefined
);
Expand Down Expand Up @@ -66,7 +66,7 @@ test("NTProvider throws error if team number is changed after connection is crea
test("NTProvider creates NT Instance using URI", () => {
render(<NTProvider uri={"test"}></NTProvider>);

expect(NetworkTables.createInstanceByURI).toHaveBeenCalledWith(
expect(NetworkTables.getInstanceByURI).toHaveBeenCalledWith(
"test",
undefined
);
Expand Down
4 changes: 2 additions & 2 deletions test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import "@testing-library/jest-dom/extend-expect";
import { NetworkTables } from "ntcore-ts-client";
import { MockedNetworkTables } from "./mocks";

jest.spyOn(NetworkTables, "createInstanceByTeam").mockReturnValue(
jest.spyOn(NetworkTables, "getInstanceByTeam").mockReturnValue(
MockedNetworkTables
);

jest.spyOn(NetworkTables, "createInstanceByURI").mockReturnValue(
jest.spyOn(NetworkTables, "getInstanceByURI").mockReturnValue(
MockedNetworkTables
);

Expand Down
6 changes: 3 additions & 3 deletions test/useNTState.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React from "react";
import { NTProvider, useNTState } from "../src";
import { NetworkTableTypeInfos } from "ntcore-ts-client";
import { NetworkTablesTypeInfos } from "ntcore-ts-client";
import { render, act, fireEvent } from "@testing-library/react";
import { MockedTopic } from "./mocks";

const TestComponent = () => {
const [state] = useNTState("test", NetworkTableTypeInfos.kBoolean, false);
const [state] = useNTState("test", NetworkTablesTypeInfos.kBoolean, false);
return <div>{state.toString()}</div>;
};

const TestComponentUpdate = () => {
const [state, setState] = useNTState<string>(
"test",
NetworkTableTypeInfos.kString,
NetworkTablesTypeInfos.kString,
"Test"
);
return (
Expand Down
6 changes: 3 additions & 3 deletions test/useNTValue.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React from "react";
import { NTProvider, useNTValue } from "../src";
import { NetworkTableTypeInfos } from "ntcore-ts-client";
import { NetworkTablesTypeInfos } from "ntcore-ts-client";
import { render, act } from "@testing-library/react";
import { MockedTopic } from "./mocks";

const TestComponent = () => {
const state = useNTValue("test", NetworkTableTypeInfos.kBoolean, false);
const state = useNTValue("test", NetworkTablesTypeInfos.kBoolean, false);
return <div>{state.toString()}</div>;
};

const StringComponent = () => {
const state = useNTValue<string>(
"test",
NetworkTableTypeInfos.kString,
NetworkTablesTypeInfos.kString,
"default"
);
return <div>{state}</div>;
Expand Down
85 changes: 50 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@
resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.14.2.tgz#c3ec604a0b54b9a9b87e9735dfc59e1a5da6a5fb"
integrity sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==

"@msgpack/msgpack@2.8.0":
"@msgpack/msgpack@^2.8.0":
version "2.8.0"
resolved "https://registry.yarnpkg.com/@msgpack/msgpack/-/msgpack-2.8.0.tgz#4210deb771ee3912964f14a15ddfb5ff877e70b9"
integrity sha512-h9u4u/jiIRKbq25PM+zymTyW6bhTzELvOoUd+AvYriWOAKpLGnIamaET3pnHYoI5iYphAHBI4ayx0MehR+VVPQ==
Expand Down Expand Up @@ -6012,7 +6012,7 @@ isomorphic-unfetch@^3.1.0:
node-fetch "^2.6.1"
unfetch "^4.2.0"

isomorphic-ws@5.0.0:
isomorphic-ws@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-5.0.0.tgz#e5529148912ecb9b451b46ed44d53dae1ce04bbf"
integrity sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==
Expand Down Expand Up @@ -7066,10 +7066,10 @@ mkdirp@^2.1.6:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-2.1.6.tgz#964fbcb12b2d8c5d6fbc62a963ac95a273e2cc19"
integrity sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==

mock-socket@9.2.1:
version "9.2.1"
resolved "https://registry.yarnpkg.com/mock-socket/-/mock-socket-9.2.1.tgz#cc9c0810aa4d0afe02d721dcb2b7e657c00e2282"
integrity sha512-aw9F9T9G2zpGipLLhSNh6ZpgUyUl4frcVmRN08uE1NWPWg43Wx6+sGPDbQ7E5iFZZDJW5b5bypMeAEHqTbIFag==
mock-socket@9.3.1:
version "9.3.1"
resolved "https://registry.yarnpkg.com/mock-socket/-/mock-socket-9.3.1.tgz#24fb00c2f573c84812aa4a24181bb025de80cc8e"
integrity sha512-qxBgB7Qa2sEQgHFjj0dSigq7fX4k6Saisd5Nelwp2q8mlbAFh5dHV9JTTlF8viYJLSSWgMCZFUom8PJcMNBoJw==

mri@^1.2.0:
version "1.2.0"
Expand Down Expand Up @@ -7195,18 +7195,18 @@ npmlog@^5.0.1:
gauge "^3.0.0"
set-blocking "^2.0.0"

ntcore-ts-client@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/ntcore-ts-client/-/ntcore-ts-client-0.2.1.tgz#b2251d6be8374cb29b25a2d08b58c21977808270"
integrity sha512-YrTe1cPEqG/VE2LoQr3dteadKb1I4vOCYA7T4IKrPYced1ngj2e07Ce6Jga5MTvrDrVnHdXhuRZF4iJBJQU5VQ==
ntcore-ts-client@^2.0.0-beta.3:
version "2.0.0-beta.3"
resolved "https://registry.yarnpkg.com/ntcore-ts-client/-/ntcore-ts-client-2.0.0-beta.3.tgz#d79ecd79a5c61e332b783488798bf5255b26786e"
integrity sha512-rwEWHnEL3Lv2lb3t1MdrBIBOR/bFKp+8eisefffnUYaRHlxGdGz/UZKrtTj8DTBDulEdwOKdh4wE2qs9VsdGAA==
dependencies:
"@msgpack/msgpack" "2.8.0"
isomorphic-ws "5.0.0"
mock-socket "9.2.1"
tslib "2.5.0"
uuid "9.0.0"
ws "8.13.0"
zod "3.21.4"
"@msgpack/msgpack" "^2.8.0"
isomorphic-ws "^5.0.0"
mock-socket "9.3.1"
tslib "2.6.2"
uuid "^9.0.1"
ws "^8.16.0"
zod "^3.22.4"

nwsapi@^2.2.2:
version "2.2.2"
Expand Down Expand Up @@ -8764,16 +8764,21 @@ ts-node@^10.8.1:
v8-compile-cache-lib "^3.0.1"
yn "3.1.1"

tslib@2.5.0, tslib@^2, tslib@^2.0.1, tslib@^2.1.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==
tslib@2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==

tslib@^1.13.0, tslib@^1.9.3:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@^2, tslib@^2.0.1, tslib@^2.1.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==

tslib@^2.4.0:
version "2.5.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.2.tgz#1b6f07185c881557b0ffa84b111a0106989e8338"
Expand Down Expand Up @@ -8997,16 +9002,21 @@ utils-merge@1.0.1:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==

uuid@9.0.0, uuid@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==

uuid@^8.3.0:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

uuid@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==

uuid@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30"
integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==

v8-compile-cache-lib@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
Expand Down Expand Up @@ -9254,18 +9264,23 @@ write-file-atomic@^4.0.2:
imurmurhash "^0.1.4"
signal-exit "^3.0.7"

ws@8.13.0, ws@^8.11.0, ws@^8.2.3:
version "8.13.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==

ws@^6.1.0:
version "6.2.2"
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.2.tgz#dd5cdbd57a9979916097652d78f1cc5faea0c32e"
integrity sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==
dependencies:
async-limiter "~1.0.0"

ws@^8.11.0, ws@^8.2.3:
version "8.13.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==

ws@^8.16.0:
version "8.16.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.16.0.tgz#d1cd774f36fbc07165066a60e40323eab6446fd4"
integrity sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==

xml-name-validator@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-4.0.0.tgz#79a006e2e63149a8600f15430f0a4725d1524835"
Expand Down Expand Up @@ -9361,7 +9376,7 @@ z-schema@~5.0.2:
optionalDependencies:
commander "^9.4.1"

zod@3.21.4:
version "3.21.4"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.21.4.tgz#10882231d992519f0a10b5dd58a38c9dabbb64db"
integrity sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==
zod@^3.22.4:
version "3.22.4"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff"
integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==

0 comments on commit 3a77b49

Please sign in to comment.