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

superMap should allow overriding behaviors to be added at config time. #247

Closed
bmomberger-bitovi opened this issue Feb 1, 2017 · 4 comments

Comments

@bmomberger-bitovi
Copy link
Contributor

bmomberger-bitovi commented Feb 1, 2017

Condensed conversation motivating this:

[Client] How can we override save() when using a superMap
[Client] I tried adding a create(), update(), createData() and updateData() methods in myModel = DefineMap.extend({ here }). Then use superMap to map myModel
[Me] That’s a common mistake when moving from can.Model to can-connect
[Me] createData() and updateData() (or even save()) have to be overridden on the connection, not on the map.
[Me] But superMap() is unhelpful because it doesn’t expose the chain of connections.  It only lets you set the configuration object, on which you can specify *some* (but not *all*) functions to be overridden.
[Me] The steps to take are:
1) put updateData() and createData() (or save()) on the config object for superMap() and see if they are hit when saving.
[Me] If so great.  If not,
2) replace superMap with a call to connect that specifies the same set of connections as superMap does, but add your own connection to the *end* of the list.

It would be nice if we could just extend superMaps with an extra behavior when creating them. Something like:

superMap({
  name: "foo",
  url: "/api/foo",
  Map: Foo,
  List: Foo.List,
  extraBehaviors: [connect.behave(function(base) {
    return {
      save: function(map) {
         return map.validate().then(base.save.bind(this, map));
      }
   }
  })]
})
@justinbmeyer
Copy link
Contributor

Thanks. I'm pretty sure there is another issue just like this in here.

@bmomberger-bitovi
Copy link
Contributor Author

#87 is related but focused on manipulating the cache connection. We could address both in one effort.

@bmomberger-bitovi
Copy link
Contributor Author

In addition to this it would be helpful to standardize or formalize which functions can be overridden on the config. Some can be, like parseListData and serializeInstance. Some can't, like save and updateData.

@justinbmeyer
Copy link
Contributor

Closing for #288

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

No branches or pull requests

2 participants