Skip to content
This repository has been archived by the owner on Nov 27, 2022. It is now read-only.

Commit

Permalink
Explicitly disallow non-string LDflex expressions.
Browse files Browse the repository at this point in the history
They currently trigger infinite rerenders,
because the passed object is always different:
#15
  • Loading branch information
RubenVerborgh committed Mar 21, 2019
1 parent 54ab590 commit 6915833
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/hooks/useLDflex.js
Expand Up @@ -11,7 +11,10 @@ const none = {};
* Evaluates the Solid LDflex expression.
* Returns an array of [result, pending, error].
*/
export default function useLDflex(expression, listMode = false) {
export default function useLDflex(expression = '', listMode = false) {
if (typeof expression !== 'string')
throw new Error('Only LDflex string expressions are currently supported.');

// The user's WebID and recent updates might influence the evaluation
const webId = useWebId();
const latestUpdate = useLiveUpdate();
Expand Down
8 changes: 3 additions & 5 deletions test/hooks/useLDflex-test.js
Expand Up @@ -52,11 +52,9 @@ describe('useLDflex', () => {
expect(evaluator.evaluate).toHaveBeenCalledTimes(1);
});

it('does not re-evaluate a Promise when a user logs in', () => {
renderHook(() => useLDflex(Promise.resolve(), true));
evaluator.evaluate.mockClear();
auth.mockWebId('https://example.org/profile#me');
expect(evaluator.evaluate).toHaveBeenCalledTimes(0);
it('does not yet support non-string LDflex expressions', () => {
expect(() => useLDflex(Promise.resolve()))
.toThrow('Only LDflex string expressions are currently supported.');
});

it('re-evaluates when the UpdateContext changes', () => {
Expand Down

0 comments on commit 6915833

Please sign in to comment.