-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
added an explicit typecast for Ember Array #23609
Conversation
This may be not be the best change, but I'm running Ember CLI 4.9.2 and needed to make this change to get past the error on `pushObject()` and enumeration. Is there a better way to fix this? Something got deprecated/changed in 4.x that is making your example (and most of what I find on StackOverflow) not work.
This seems like the wrong solution, given the deprecation of |
Okay, seems like also adding |
@@ -214,6 +214,8 @@ This is because Ember extends JavaScript's Array prototype by default, giving us | |||
There are dozens of these methods, including `pushObjects()`, `insertAt()`, or `popObject()`, which can be used with any type (not just Objects). | |||
Ember's [ArrayProxy](https://api.emberjs.com/ember/4.2/classes/ArrayProxy) also gives us more handy methods, like `isAny()`, `findBy()`, and `filterBy()` to make life easier. | |||
|
|||
**Note:** If you receive a console error around the `pushObject()` function (e.g. `this.todos.pushObject is not a function`) you may need to explicitly typecast your JavaScript Array into an Ember Array using the `A()` method. Add `import { A } from '@ember/array';` at the top of the `todo-data.js` file, and replace `@tracked todos = []` with `@tracked todos = A()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, instead of adding this disclaimer, we should update to using TrackedArray
, which has regular push <3
Haha thank you, I'm a total newbie here. When I tried to use TrackedArray I
got an error that there was a missing package, and I don't see it in the
docs. Is it brand new? Happy to write the pull request if you can give me
some gentle guidance
…On Fri, Jan 13, 2023, 1:37 PM NullVoxPopuli ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
files/en-us/learn/tools_and_testing/client-side_javascript_frameworks/ember_interactivity_events_state/index.md
<#23609 (comment)>:
> @@ -214,6 +214,8 @@ This is because Ember extends JavaScript's Array prototype by default, giving us
There are dozens of these methods, including `pushObjects()`, `insertAt()`, or `popObject()`, which can be used with any type (not just Objects).
Ember's [ArrayProxy](https://api.emberjs.com/ember/4.2/classes/ArrayProxy) also gives us more handy methods, like `isAny()`, `findBy()`, and `filterBy()` to make life easier.
+**Note:** If you receive a console error around the `pushObject()` function (e.g. `this.todos.pushObject is not a function`) you may need to explicitly typecast your JavaScript Array into an Ember Array using the `A()` method. Add `import { A } from ***@***.***/array';` at the top of the `todo-data.js` file, and replace ***@***.*** todos = []` with ***@***.*** todos = A()`.
I think, instead of adding this disclaimer, we should update to using
TrackedArray, which has regular push <3
—
Reply to this email directly, view it on GitHub
<#23609 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABVHNVO2UTSMTDFOAIIICLWSFD7JANCNFSM6AAAAAAT2KB5WI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Welcome! No worries! It is newish, and does need to be installed, there is an RFC that proposed adding it by default, so i suppose it'll show up by default fairly soon™ Your contributions mean a lot! <3 |
@mrisher Thanks for your PR! Do you want to get back to it and make the changes @NullVoxPopuli proposed? |
@mrisher friendly ping |
So Sorry, I overlooked this note before and forgot about this. I will check whether I can implement TrackedArray myself in the next few days, if not I'll call for help. Thank you! |
Hi: I tried to update to use TrackedArray tonight and am hitting bugs; I may not be familiar enough with the Ember internals to debug -- basically, I updated the variable to |
can you provide the code you had?, the whole file, ideally? <3 |
Sure thing. This is the file adapted from your example code, where Maybe I need to declare the object type for the TrackedArray? And IIUC the TrackedArray supports Thanks for the help! |
@mrisher in that repo you provided, does it work without firebase? I don't have an account
what you did should have worked 🤔 |
Ah, I see the problem, it's the assignment when it reads the json blob back from firebase here. Is there an idiomatic way to do a deep copy instead of assignment at this line? Or should I rewrite that whole |
@mrisher @NullVoxPopuli sorry, seems like this is stuck (again). I'm closing. Feel free to come back to it, though. |
This may be not be the best change, but I'm running Ember CLI 4.9.2 and needed to make this change to get past the error on
pushObject()
and enumeration. Is there a better way to fix this? Something got deprecated/changed in 4.x that is making your example (and most of what I find on StackOverflow) not work.Description
Motivation
Additional details
Related issues and pull requests