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

global: general improvements #24

Merged

Conversation

drjova
Copy link
Member

@drjova drjova commented Sep 2, 2016

DO NOT merge yet

@drjova drjova changed the title global: general improvements WIPglobal: general improvements Sep 2, 2016
@drjova drjova changed the title WIPglobal: general improvements WIP global: general improvements Sep 2, 2016
@drjova drjova force-pushed the global-general-improvements branch 2 times, most recently from 6b92654 to e09b695 Compare September 2, 2016 07:57
@drjova drjova changed the title WIP global: general improvements global: general improvements Sep 2, 2016
@drjova drjova added this to the v1.0.0 milestone Sep 2, 2016
return {
url: url,
method: (method || 'PUT').toUpperCase(),
data: _data,
Copy link
Member

Choose a reason for hiding this comment

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

👍

@drjova drjova force-pushed the global-general-improvements branch 2 times, most recently from 124175c to 5e3b964 Compare September 9, 2016 15:34
@drjova
Copy link
Member Author

drjova commented Sep 9, 2016

The PR has been updated with a more DRY approach for different use cases, it's possible to change the data and clean logic with a service decorator:

.config([ '$provide', function($provide) {

  $provide.decorator('InvenioRecordsAPI', [
    '$delegate',
    function myServiceDecorator($delegate) {

      // keep the existing function
      var getData = $delegate.getData;

      function newCleanData(data, unwanted) {
        // unicorns and stuff
        return data;
      }

      function newGetData(model, extraParams, endpoints) {
        var _model = {
            metadata: model
        };
        // More unicorns and stuff

        // Pass the arguments to the existing function without re-writting the code
        getData.apply($delegate, _model, extraParams, endpoints);
      }

      // Override the cleanData
      $delegate.cleanData = newCleanData;

      // Override the getData
      $delegate.getData = newGetData;

      // return the delegate
      return $delegate;
    }
  ]);
}]);

Signed-off-by: Harris Tzovanakis <me@drjova.com>
@pamfilos
Copy link
Member

pamfilos commented Sep 9, 2016

👍 LGTM!

@lnielsen lnielsen self-assigned this Sep 9, 2016
@ioannistsanaktsidis
Copy link

This one works for me and @pamfilos. I think it can go on.
cc @jirikuncar , @lnielsen

@jirikuncar jirikuncar merged commit 303e2eb into inveniosoftware:master Sep 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants