Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-callable trackedFunction #559

Closed
wants to merge 1 commit into from

Conversation

velrest
Copy link

@velrest velrest commented Jul 12, 2022

No description provided.

@velrest
Copy link
Author

velrest commented Jul 12, 2022

I haven't tested this fully with tracking context yet but its a work in progress and i figured i'd open a draft pr.

@velrest
Copy link
Author

velrest commented Jul 12, 2022

I know it's not necessarily nice to put values on a function object, but i think the ergonomics of this approach are quite nice. I also played around a bit with putting a "re-execute" function onto the State but i had some problems with context and reassigning the values.

@velrest velrest force-pushed the retry-trackedfunction branch 3 times, most recently from 066fb9a to ad279cf Compare July 12, 2022 09:22
@velrest velrest changed the title retry trackedfunction re-callable trackedFunction Jul 12, 2022
return propertyValue.state;
};

Object.defineProperty(propertyValue, "value", {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This likely won't be TS safe -- any reason to not use a class?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how you can define a class which can then be called as a function. Just out of interest, do you know how to do this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why call the class as a function? it can have a method that can be called

@NullVoxPopuli
Copy link
Owner

had some problems with context and reassigning the values.

I think we'll still want to explore putting things on the State class -- what problems were you running in to?

@velrest
Copy link
Author

velrest commented Jul 12, 2022

had some problems with context and reassigning the values.

I think we'll still want to explore putting things on the State class -- what problems were you running in to?

Out of curiosity, is it because of the API or maybe because the implementation is a bit messy?

@NullVoxPopuli
Copy link
Owner

Out of curiosity, is it because of the API or maybe because the implementation is a bit messy?

classes have way better type inference than the dynamic approach presently implemented in this PR. ember-resources is aiming for maximum Glint support with maximum type inference ability (yay!) 🥳

@velrest
Copy link
Author

velrest commented Jul 12, 2022

I see, that`s a very good argument 😄 .

I'm not really a typescript user and am more used to a more "functional" programming style so that's why i tried to implement it a bit more declarative and in a dynamic way.

I'll have a look again and put this into the State.

@velrest velrest marked this pull request as ready for review August 29, 2022 08:08
@velrest velrest force-pushed the retry-trackedfunction branch 5 times, most recently from 0eaaca5 to c867dc0 Compare August 29, 2022 14:21
@@ -1,15 +1,22 @@
import { tracked } from '@glimmer/tracking';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why so many formatting changes here? can you revert these? makes the diff a bit noisy

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, prettier format on save 😓

@velrest velrest force-pushed the retry-trackedfunction branch from c867dc0 to 8421b63 Compare August 30, 2022 08:24

(async () => {
return resource<TrackedFunctionProperty<Return>>(context, (hooks) => {
const getValue = async (state: State<Return>) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this function move inside the new class?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@velrest velrest force-pushed the retry-trackedfunction branch 4 times, most recently from e73f949 to 6cbc23f Compare September 29, 2022 16:58
@velrest
Copy link
Author

velrest commented Sep 29, 2022

@NullVoxPopuli I implemented the function on the class as you proposed an the test is now green, feel free to have a look at this again 😄

@velrest velrest force-pushed the retry-trackedfunction branch from 6cbc23f to 2f5d0d5 Compare September 29, 2022 17:01
return resource<State<Return>>(context, (hooks) => {
let state = new State(initialValue);
return resource<TrackedFunctionProperty<Return>>(context, (hooks) => {
return new TrackedFunctionProperty(fn, hooks, initialValue);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the return type is a bit of a breaking change -- any chance you can combine the two classes, in in the execute method, "reset" the state values?

{ id: 2, page: 2 },
]);

const value = await foo.data.execute();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add assertions for what the value properties are supposed to be after execute is invoked?

maybe something like:

let almostValue = foo.data.execute();
// assert stuff
assert...

let value = await almostValue


constructor(public initialValue?: Value) {}
@action
execute() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "execute" for the name?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not happy with it but perform is no kind of reserved for tasks, run, call etc also seem a bit off and retry is imo trying something that has failed again. Whats your opinion?

@NullVoxPopuli
Copy link
Owner

I gave a shot at this here: #665

thoughts?

@NullVoxPopuli
Copy link
Owner

Gonna close in favor of: #665

@velrest , thanks a ton for pushing this forward!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants