Skip to content

Lots of Updates#14

Open
twaite wants to merge 36 commits intomasterfrom
feature/observables
Open

Lots of Updates#14
twaite wants to merge 36 commits intomasterfrom
feature/observables

Conversation

@twaite
Copy link
Copy Markdown
Owner

@twaite twaite commented Mar 2, 2019

@twaite twaite self-assigned this Mar 2, 2019
@twaite twaite added enhancement New feature or request docs labels Mar 2, 2019
@twaite twaite added this to the MVP milestone Mar 2, 2019
@twaite twaite requested review from jcampuza and sliptype March 2, 2019 01:06
@jcampuza jcampuza mentioned this pull request Mar 2, 2019
}

hookCallIndex++;
deps = deps != null ? deps : null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why is this line necessary?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I believe it has to do w/ typescript validation. @jcampuza ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That’s what I thought at first but the type after this statement will still be <any[] | null>. When th conditional down below checks for null, that’s when typescript will recognize it as <any[]>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's to force deps to be of type <any[] | null>. Before this statement it would be of type <any[] | null | undefined>. In essence it's casting it so that it's not undefined.

Copy link
Copy Markdown
Collaborator

@jcampuza jcampuza Mar 10, 2019

Choose a reason for hiding this comment

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

React's hooks implementation does a similar check, a lot of this was inspired by that.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks! I missed the ? in the input params.

Object.defineProperty(obj, '__ancestors', {
value: ancestors,
enumerable: false,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why remove this?

}
};

const _handleArrayFunctions = (scope: IEmberHooksComponent, target: any, prop: string): Function => {
Copy link
Copy Markdown
Collaborator

@jcampuza jcampuza Mar 11, 2019

Choose a reason for hiding this comment

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

I think we can narrow down the type of target here to any[] since this should only be called with arrays.

// TODO: tw - should this be an object instead of ifs?
const emberArray = scope.get(target.__ancestors.join());
if (prop === 'push') {
return (val: any) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we may want to create separate functions for these, or at least give them names for debugging purposes, and it'd be a slight perf enhancement to not create inline functions.

@jcampuza
Copy link
Copy Markdown
Collaborator

Left a few comments, but these could also be addressed as part of another PR as well, waiting for this to get merged before starting on any other hooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants