Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

$mdCompiler breaks if called multiple times with the same options object #2614

Closed
rochdev opened this issue Apr 29, 2015 · 4 comments
Closed
Assignees
Milestone

Comments

@rochdev
Copy link
Contributor

rochdev commented Apr 29, 2015

This is because $mdCompiler modifies the source object and gets confused if it receives the same object again later. Treating the options object as immutable would solve the issue at a very small performance cost (copying properties).

I will try to submit a pull request this weekend.

@ThomasBurleson
Copy link
Contributor

@rochdev - look forward to seeing your ideas/solution.

@ThomasBurleson ThomasBurleson added this to the 0.10.0 milestone Apr 29, 2015
@ThomasBurleson ThomasBurleson self-assigned this Apr 29, 2015
rochdev added a commit to rochdev/material that referenced this issue May 2, 2015


Objects passed to a function should be considered immutable

 to avoid unexpected side-effects

Closes angular#2614
@ThomasBurleson
Copy link
Contributor

@rochdev - In what scenario would the $mdCompiler receive the same object multiple times ?

@rochdev
Copy link
Contributor Author

rochdev commented May 3, 2015

In my case it's an overlay service which we built as part of our own UI framework which is using angular-material core for utilities. When creating a new instance, it takes options which are then reused every time you call show on the that instance and it's currently hidden. It is functionally similar to $$interimElement.

While I can (and did) just clone the options on every show, it is missing the point: modifying an object passed as parameter to a function is bad practice when it would be unexpected (if the purpose of the function is not explicitly mutation of the object).

Also, it should be up to the caller whether or not the callee is called multiple times, not the callee (unless there is a compelling reason to prevent it).

What do you think?

@ThomasBurleson
Copy link
Contributor

@rochdev - Totally agree that the failure point (weakness) needs to be resolved. My earlier question was simply wondering why you were having scenarios with multiple calls. $mdCompiler should not maintain state, no force expectations on the caller to protect itself.

@ThomasBurleson ThomasBurleson modified the milestones: 0.10.0, 0.11.0 Jun 16, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants