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

Singletonable mixin #3

Merged
merged 4 commits into from
Apr 24, 2016
Merged

Singletonable mixin #3

merged 4 commits into from
Apr 24, 2016

Conversation

osuushi
Copy link
Contributor

@osuushi osuushi commented Apr 23, 2016

No description provided.

varargs = arguments._.tail();

// Storage for the the singleton object, once it is created
var singleton;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally I think this would be Constructor._singleton or something like that so that people could mock/override it

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... I guess that won't really work because of the name you're using, but you could provide a setter method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a previous iteration, I had set configurable: true, thinking that would make it so subclasses could override it. But then I realized that that's not necessary for the subclass case, and took it off. Mocking is a good point though, so I think you're right.

I have a trick for this kind of situation where you define a property as a configurable property, but then set it when it's accessed, so it acts exactly like normal property. That'll be good because then we can use autoMock too.

delete object[name];
object[name] = value;
return value;
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I just realized this also needs a setter, or you won't be able to set it if it's never been accessed.

@benbernard benbernard merged commit a759146 into master Apr 24, 2016
@benbernard benbernard deleted the singletonable branch April 24, 2016 19:24
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.

None yet

2 participants