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

Allow resource instances to be created from a base class #51

Merged
merged 2 commits into from
Feb 24, 2015

Conversation

mhwinkler
Copy link
Contributor

Per the discussion here: https://groups.io/org/groupsio/jsdata/thread/33314

Instead of useClass being a simple boolean operator, I would suggest we allow for two data types to be passed: boolean yes/no (for a generic constructor) or a function (for our new constructor to inherit from).

In this way, instances of models would be able to inherit the properties and behavior of a given base model, rather than just being supplied with individual helpers via the methods: config.

@mhwinkler mhwinkler closed this Feb 12, 2015
@mhwinkler
Copy link
Contributor Author

Sorry - I thought that this solution would fail minification, but it appears to be passing just fine.

@mhwinkler mhwinkler reopened this Feb 12, 2015
@jmdobry
Copy link
Member

jmdobry commented Feb 12, 2015

So far as I know, eval is the only way to create a named function at runtime, rather than at parse time.

Instead of

var useClass = def.useClass;
eval('function ' + def['class'] + '() { useClass.call(this); }');

can't you just do

eval('function ' + def['class'] + '() { def.useClass.call(this); }');

@mhwinkler
Copy link
Contributor Author

I'm really unfamiliar with eval and how it works with minification so I'm assuming you are correct there. I think I was being overly explicit in my testing.

@jmdobry jmdobry self-assigned this Feb 17, 2015
jmdobry added a commit that referenced this pull request Feb 24, 2015
Allow resource instances to be created from a base class
@jmdobry jmdobry merged commit 0195db9 into js-data:master Feb 24, 2015
@jmdobry jmdobry removed the ready label Feb 24, 2015
@jessemorton
Copy link

It seems that the ability to use a base class may affect some other areas of JSData. For example, when I have some properties defined on my custom base class, those are showing up within the DSHasChanges() object's added property, causing a false positive that there's changes.

@jmdobry
Copy link
Member

jmdobry commented Mar 2, 2015

@jessemorton Perhaps open an issue or post on the mailing list with more information: versions, code examples, etc.

These are "static" properties attached to your base constructor function?

@jessemorton
Copy link

Opened a new issue. Let me know if I can provide more information or the like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants