45// instead of a bounding box search, we could use something like geohashes to find all nearby cities more efficiently and quickly.
46export const findNearestCityByCoord = mutation({
47 args: { coord: v.object({ lat: v.number(), lon: v.number() }) },
48 handler: async (ctx, args) => {49 const citiesInBoundingBox = await ctx.db
50 .query("search")
51 .withIndex("lon_idx", (q) =>
839 <div className="ml-4 flex justify-between">
840 {Object.entries(
841 weatherData.data.precipitationProbabilities,
842 ).map(([key, value]) => { 843 let raindropClass = "h-full w-full -mt-2";
844 if (value !== undefined && value !== null) {
845 raindropClass = clsx(
Any code paths that do not have explicit returns will return undefined
.
It is recommended to replace any implicit dead-ends that return undefined
with a return null
statement.
As a convention, undefined
signals that an unexpected value has been produced as the
result of a logical error in the program.
A null
return, on the other hand, signals that the input to a function was incorrect,
or a value was 'not found'.
Having this distinction in code helps you figure out if something was caused because of a logical error, or malformed input to a function call.
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// whoops! Implicit undefined return
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
return; // Implicit undefined return.
}
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// `null` indicates there is no such user.
return null;
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
// `null` indicates there is no such file.
return null;
}