question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamically created computed property seems to be broken in 3.1

See original GitHub issue

Hello !

I’m using dynamically generated computed property, and it seems to not work anymore in 3.1.

Here is a code sample of what I’m doing :

	setupNormalUser(currentUser) {
		Ember.set(this, "projects",
			Ember.computed("currentUser.projects.[]", "demoAccounts.@each.projects",
				() => {
					let projects = [].concat(currentUser.get("projects"))
					const demoAccounts = this.get("demoAccounts.content")
					if (Ember.isArray(demoAccounts)) {
						demoAccounts.forEach(
							(demoAccount) => projects = projects.concat(demoAccount.get("projects"))
						)
					}
					return projects
				}
			)
		)
		Ember.set(this, "accounts",
			Ember.computed("currentUser.accounts.[]", "projects.[]", function() {
				const projects = currentUser.get("projects") || [];
				return projects
					.filter(project=>!Ember.isNone(project))
					.map(project=>project.get("account.content"))
					.concat( currentUser.get("accounts"))
					.filter(a => !Ember.isNone(a)).uniq()
			})
		)
		Ember.set(this, "assetLibraries",
			Ember.computed("accounts.@each.assetLibraries", function() {
				return currentUser.get("accounts").map(
					(account) => account.get("assetLibraries").toArray()
				).reduce(
					(prev, cur) => prev.concat(cur), []
				).uniq()
			})
		)
	},
	setupSuperAdmin(currentUser) {
		this.set("projects", this.get("store").findAll("project"))
		this.set("accounts", this.get("store").findAll("account"))
		this.set("assetLibraries", this.get("store").findAll("assetLibrary"))
	},

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
rwjbluecommented, Apr 12, 2018

I’m fairly sure my prior comment is correct, and this is a duplicate of https://github.com/emberjs/ember.js/issues/16427. Essentially doing this:

Ember.set(someObject, Ember.computed('depKey', function() { /* some calculation */ }));

Is not a thing we actually support. The quick solution in your snippet above would be to move from Ember.set to Ember.defineProperty (which works all the way back to Ember 1.x).

Something like this...
setupNormalUser(currentUser) {
		Ember.defineProperty(this, "projects",
			Ember.computed("currentUser.projects.[]", "demoAccounts.@each.projects",
				() => {
					let projects = [].concat(currentUser.get("projects"))
					const demoAccounts = this.get("demoAccounts.content")
					if (Ember.isArray(demoAccounts)) {
						demoAccounts.forEach(
							(demoAccount) => projects = projects.concat(demoAccount.get("projects"))
						)
					}
					return projects
				}
			)
		)
		Ember.defineProperty(this, "accounts",
			Ember.computed("currentUser.accounts.[]", "projects.[]", function() {
				const projects = currentUser.get("projects") || [];
				return projects
					.filter(project=>!Ember.isNone(project))
					.map(project=>project.get("account.content"))
					.concat( currentUser.get("accounts"))
					.filter(a => !Ember.isNone(a)).uniq()
			})
		)
		Ember.defineProperty(this, "assetLibraries",
			Ember.computed("accounts.@each.assetLibraries", function() {
				return currentUser.get("accounts").map(
					(account) => account.get("assetLibraries").toArray()
				).reduce(
					(prev, cur) => prev.concat(cur), []
				).uniq()
			})
		)
	},
1reaction
olivierchatrycommented, Apr 17, 2018

Closing it, as it was a miss-use of the system.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic computed property name - vue.js
When using it in a method, you might need to check it's existence depending on the call sequence. computed: { element() { return...
Read more >
XPath and XQuery Functions and Operators 3.1
As explained in XDM, document, element and processing-instruction nodes have a base-uri property which may be empty. The base-uri property for ...
Read more >
Model validation in ASP.NET Core MVC and Razor Pages
Create an action method for JavaScript to call. The jQuery Validation remote method expects a JSON response: true means the input data is...
Read more >
SystemVerilog 3.1a Language Reference Manual
Four subcommittees worked on various aspects of the SystemVerilog 3.1 ... class extension allows objects to be created and destroyed dynamically.
Read more >
Developer Guide :: NVIDIA Deep Learning TensorRT ...
The physical partitions provide dedicated compute and memory slices with QoS ... 3.1.1. Creating a Network Definition. After the builder has been created, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found