haystack-react
Advanced tools
Comparing version 3.0.3 to 3.0.4
/* | ||
* Copyright (c) 2020, J2 Innovations. All Rights Reserved | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
/* eslint prefer-const: "off" */ | ||
@@ -32,31 +23,29 @@ import { useState, useEffect, createContext, useContext, useRef } from 'react'; | ||
let cancel = false; | ||
function doGetGrid() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const wasLoading = gridData.isLoading; | ||
gridData.isLoading = true; | ||
// If a grid wasn't loading before it is now so force an | ||
// update in the UI. | ||
if (!wasLoading) { | ||
forceUpdate(); | ||
} | ||
const grid = yield getGrid(); | ||
if (!cancel) { | ||
gridData.grid = grid; | ||
} | ||
async function doGetGrid() { | ||
try { | ||
const wasLoading = gridData.isLoading; | ||
gridData.isLoading = true; | ||
// If a grid wasn't loading before it is now so force an | ||
// update in the UI. | ||
if (!wasLoading) { | ||
forceUpdate(); | ||
} | ||
catch (err) { | ||
if (!cancel) { | ||
gridData.error = err; | ||
} | ||
const grid = await getGrid(); | ||
if (!cancel) { | ||
gridData.grid = grid; | ||
} | ||
finally { | ||
if (!cancel) { | ||
++gridData.loads; | ||
gridData.isLoading = false; | ||
} | ||
// Force an update after everything has completed. | ||
forceUpdate(); | ||
} | ||
catch (err) { | ||
if (!cancel) { | ||
gridData.error = err; | ||
} | ||
}); | ||
} | ||
finally { | ||
if (!cancel) { | ||
++gridData.loads; | ||
gridData.isLoading = false; | ||
} | ||
// Force an update after everything has completed. | ||
forceUpdate(); | ||
} | ||
} | ||
@@ -123,5 +112,5 @@ doGetGrid(); | ||
const result = useGrid({ | ||
getGrid: () => __awaiter(this, void 0, void 0, function* () { | ||
getGrid: async () => { | ||
return ids.length ? client.record.readByIds(ids) : new HGrid(); | ||
}), | ||
}, | ||
dependencies: [JSON.stringify(ids), client, ops, refreshes], | ||
@@ -147,3 +136,3 @@ }); | ||
result = useGrid({ | ||
getGrid: () => __awaiter(this, void 0, void 0, function* () { return String(id) ? client.ops.read(filter) : new HGrid(); }), | ||
getGrid: async () => String(id) ? client.ops.read(filter) : new HGrid(), | ||
dependencies, | ||
@@ -154,7 +143,5 @@ }); | ||
result = useGrid({ | ||
getGrid: () => __awaiter(this, void 0, void 0, function* () { | ||
return String(id) | ||
? (yield client.record.readById(id)).toGrid() | ||
: new HGrid(); | ||
}), | ||
getGrid: async () => String(id) | ||
? (await client.record.readById(id)).toGrid() | ||
: new HGrid(), | ||
dependencies, | ||
@@ -179,3 +166,3 @@ }); | ||
result = useGrid({ | ||
getGrid: () => __awaiter(this, void 0, void 0, function* () { return filter ? client.ops.read(filter) : new HGrid(); }), | ||
getGrid: async () => filter ? client.ops.read(filter) : new HGrid(), | ||
dependencies, | ||
@@ -186,3 +173,3 @@ }); | ||
result = useGrid({ | ||
getGrid: () => __awaiter(this, void 0, void 0, function* () { return filter ? client.record.readByFilter(filter) : new HGrid(); }), | ||
getGrid: async () => filter ? client.record.readByFilter(filter) : new HGrid(), | ||
dependencies, | ||
@@ -203,3 +190,3 @@ }); | ||
const result = useGrid({ | ||
getGrid: () => __awaiter(this, void 0, void 0, function* () { return client.ext.eval(expr); }), | ||
getGrid: async () => client.ext.eval(expr), | ||
dependencies: [expr, client, refreshes], | ||
@@ -206,0 +193,0 @@ }); |
/* | ||
* Copyright (c) 2021, J2 Innovations. All Rights Reserved | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { useEffect, useState } from 'react'; | ||
@@ -36,7 +27,7 @@ import { useClient } from './client'; | ||
const writeFunc = write | ||
? (val, options) => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield (write === null || write === void 0 ? void 0 : write(val, options)); | ||
? async (val, options) => { | ||
const result = await (write === null || write === void 0 ? void 0 : write(val, options)); | ||
setCurrentValue(val); | ||
return result; | ||
}) | ||
} | ||
: undefined; | ||
@@ -43,0 +34,0 @@ useEffect(() => { |
/* | ||
* Copyright (c) 2021, J2 Innovations. All Rights Reserved | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { useEffect, useState } from 'react'; | ||
@@ -38,7 +29,7 @@ import { useClient } from './client'; | ||
const writeFunc = write | ||
? (val) => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield (write === null || write === void 0 ? void 0 : write(val)); | ||
? async (val) => { | ||
const result = await (write === null || write === void 0 ? void 0 : write(val)); | ||
setCurrentValue(val); | ||
return result; | ||
}) | ||
} | ||
: undefined; | ||
@@ -45,0 +36,0 @@ useEffect(() => { |
/* | ||
* Copyright (c) 2020, J2 Innovations. All Rights Reserved | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
/* eslint prefer-const: "off" */ | ||
@@ -43,60 +34,58 @@ import { useEffect, useRef, useState } from 'react'; | ||
let cancel = false; | ||
function open() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const wasLoading = watchData.isLoading; | ||
watchData.isLoading = true; | ||
// If watch wasn't loading before it is now so force an | ||
// update in the UI. | ||
if (!wasLoading) { | ||
forceUpdate(); | ||
} | ||
if (!ids) { | ||
ids = filter | ||
? yield (ops | ||
? client.ops.read(filter) | ||
: client.record.readByFilter(filter)) | ||
: new HGrid(); | ||
// If the effect was closed after the network call then bail. | ||
if (cancel) { | ||
return; | ||
} | ||
watchData.grid = ids; | ||
watchData.isLoading = false; | ||
// Force an update here as we already have some valid data to render before | ||
// the watch is opened. | ||
forceUpdate(); | ||
} | ||
const watch = yield (ops | ||
? client.ops.watch | ||
: client.watch).make(display || | ||
filter || | ||
`useWatch@${new Date().toISOString()}`, ids); | ||
// If the effect was closed after opening the watch then close it and bail. | ||
async function open() { | ||
try { | ||
const wasLoading = watchData.isLoading; | ||
watchData.isLoading = true; | ||
// If watch wasn't loading before it is now so force an | ||
// update in the UI. | ||
if (!wasLoading) { | ||
forceUpdate(); | ||
} | ||
if (!ids) { | ||
ids = filter | ||
? await (ops | ||
? client.ops.read(filter) | ||
: client.record.readByFilter(filter)) | ||
: new HGrid(); | ||
// If the effect was closed after the network call then bail. | ||
if (cancel) { | ||
yield watch.close(); | ||
return watch; | ||
return; | ||
} | ||
watch.pollRate = | ||
pollRate > 0 ? pollRate : DEFAULT_POLL_RATE_SECS; | ||
watch.changed({ | ||
callback: forceUpdate, | ||
}); | ||
watchData.grid = watch.grid; | ||
watchData.grid = ids; | ||
watchData.isLoading = false; | ||
// Force an update here as we already have some valid data to render before | ||
// the watch is opened. | ||
forceUpdate(); | ||
} | ||
const watch = await (ops | ||
? client.ops.watch | ||
: client.watch).make(display || | ||
filter || | ||
`useWatch@${new Date().toISOString()}`, ids); | ||
// If the effect was closed after opening the watch then close it and bail. | ||
if (cancel) { | ||
await watch.close(); | ||
return watch; | ||
} | ||
catch (err) { | ||
if (!cancel) { | ||
watchData.error = err; | ||
} | ||
watch.pollRate = | ||
pollRate > 0 ? pollRate : DEFAULT_POLL_RATE_SECS; | ||
watch.changed({ | ||
callback: forceUpdate, | ||
}); | ||
watchData.grid = watch.grid; | ||
return watch; | ||
} | ||
catch (err) { | ||
if (!cancel) { | ||
watchData.error = err; | ||
} | ||
finally { | ||
if (!cancel) { | ||
watchData.isLoading = false; | ||
++watchData.loads; | ||
} | ||
forceUpdate(); | ||
} | ||
finally { | ||
if (!cancel) { | ||
watchData.isLoading = false; | ||
++watchData.loads; | ||
} | ||
return undefined; | ||
}); | ||
forceUpdate(); | ||
} | ||
return undefined; | ||
} | ||
@@ -110,9 +99,7 @@ const promise = open(); | ||
watchData.error = undefined; | ||
function close() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (promise) { | ||
const watch = yield promise; | ||
watch === null || watch === void 0 ? void 0 : watch.close(); | ||
} | ||
}); | ||
async function close() { | ||
if (promise) { | ||
const watch = await promise; | ||
watch === null || watch === void 0 ? void 0 : watch.close(); | ||
} | ||
} | ||
@@ -119,0 +106,0 @@ close(); |
{ | ||
"name": "haystack-react", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "Project Haystack utilities for building React applications", | ||
@@ -37,4 +37,4 @@ "main": "dist/index", | ||
"eslint-plugin-react": "^7.29.4", | ||
"haystack-core": "^2.0.29", | ||
"haystack-nclient": "^3.0.12", | ||
"haystack-core": "^2.0.30", | ||
"haystack-nclient": "^3.0.16", | ||
"husky": "^4.3.5", | ||
@@ -54,4 +54,4 @@ "lint-staged": "^12.3.7", | ||
"peerDependencies": { | ||
"haystack-core": "^2.0.29", | ||
"haystack-nclient": "^3.0.12" | ||
"haystack-core": "^2.0.30", | ||
"haystack-nclient": "^3.0.16" | ||
}, | ||
@@ -58,0 +58,0 @@ "husky": { |
{ | ||
"compilerOptions": { | ||
"module": "ES6", | ||
"target": "ES2017", | ||
"module": "ESNext", | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"target": "ES6", | ||
"strict": true, | ||
@@ -8,0 +8,0 @@ "noImplicitAny": true, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
88418
1602