-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Is it possible to get rid of side effects when evaluating api.tx
etc?
#4994
Comments
No idea, but actually saw that issue you logged, aka works in Node doesn't quite work in Deno. If I had to take a guess... It is quite possibly due to the fact that However... looking at your specific log, it seems to be due to the use of assertResult - not 100% sure these are all needed anymore (it used to), I actually saw that earlier this week and for most of these I do believe the object would never be null or undefined. So if you are in the mood for a small PR - would suggest just dropping all of these in |
Thanks, I'll give it a shot. BTW how are the files in https://github.com/polkadot-js/build-deno.land generated? I'd like to first test it locally before submitting a PR. |
On build, the deno output is placed in |
api.tx
etc?api.tx
etc?
I think I've found something interesting. If we define Experiment: Create three files under current directory (bash) cat <<EOF >is.ts
export function isUndefined(value?: unknown): value is undefined {
return typeof value === "undefined";
}
export function isFunction(value: unknown): value is Function {
return typeof value === "function";
}
EOF
cat <<EOF >module.ts
import { isFunction, isUndefined } from "./is.ts";
export function assertReturnModule<T>(
value: T | undefined,
message: string | (() => string),
): T {
if (isUndefined(value)) {
throw new Error(
isFunction(message) ? message() : message,
);
}
return value;
}
EOF
cat <<EOF >init.ts
import { isFunction, isUndefined } from "./is.ts";
import { assertReturnModule } from "./module.ts";
export function assertReturnLocal<T>(
value: T | undefined,
message: string | (() => string),
): T {
if (isUndefined(value)) {
throw new Error(
isFunction(message) ? message() : message,
);
}
return value;
}
class Getter {
public name: string | undefined;
constructor(name?: string) {
this.name = name;
}
public get M(): string {
return assertReturnModule(this.name, "name cannot be null");
}
public get L(): string {
return assertReturnLocal(this.name, "name cannot be null");
}
}
let G = new Getter("v8 getter side effect check");
EOF Then start deno repl with the following flags
It indicates that we can get rid of the |
I created #5009 as a workaround, where assertReturn is replaced with equivalent inlined code. |
* Add side effect check workaround (#4994) * Update packages/api/src/base/Getters.ts Co-authored-by: Jaco <jacogr@gmail.com> * Update packages/api/src/base/Getters.ts Co-authored-by: Jaco <jacogr@gmail.com> * eslint --fix * inline isUndefined Co-authored-by: Jaco <jacogr@gmail.com>
Do you need a version published to Deno? (If you can wait a day or two, it will happen Saturday/Sunday with a new published API - if absolutely urgent, can do one manually) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query. |
I'm submitting a
What is the current behavior and expected behavior?
Tab completion is not working in some circumstances.
Pressing tab(s) on the input
api.tx.
shows nothing:Same is true for
api.query.
,api.consts.
,api.rpc.
, etc.Expected tab completion to work without patching Deno
To improve the dev experience of using https://deno.land/x/polkadot in Deno repl.
Please tell us about your environment:
Version: deno.land/x/polkadot@0.0.1
Environment:
Language:
Related: denoland/deno#14967
Adding
--v8-flags=--trace-side-effect-free-debug-evaluate
shows that evaluatingapi.tx
failed side effect check.Deno repl skips tab completion for expressions evaluated with side effects: https://github.com/denoland/deno/blob/8d82ba729937baf83011354242cabc3d50c13dc2/cli/tools/repl/editor.rs#L132
I searched for similar problems in Deno's issue history, and it seems no one encountered the same tab completion problem before.
My question: why evaluating api.tx introduces side effect and is it possible to get rid of it?
I understand that deno.land/x/polkadot is experimental, and Deno is not currently a supported target, but still would like to play with it more. Feel free to close this if it's off topic.
Thanks.
The text was updated successfully, but these errors were encountered: