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

InfinityModels managed by service + closure actions #271

Merged
merged 29 commits into from Apr 13, 2018

Conversation

snewcomer
Copy link
Collaborator

@snewcomer snewcomer commented Mar 29, 2018

InfinityModels managed by a service to provide an API to update, filter, set the list of infinityModels. Moreover, instead of bubbling actions to the route, this opens up the possibility for closure actions.

  • Infinity Loader service with replace, flush, pushObjects, and unshiftObjects methods
  • With the new service, new API for infinity-loader component to accept a closure action
  • Update README

One of the big benefits of closure actions is the ability to return a value or curry values; and although we don't necessarily need those in this example, I can see it useful for others.

Ref #272 #270

Will open up possibilities for #275

@snewcomer snewcomer added the WIP label Mar 29, 2018
@snewcomer snewcomer self-assigned this Mar 29, 2018
@snewcomer snewcomer changed the title Example with closure actions InfinityModels managed by service Apr 3, 2018
@snewcomer snewcomer changed the title InfinityModels managed by service InfinityModels managed by service + closure actions Apr 7, 2018
@snewcomer snewcomer force-pushed the sn/component-loading branch 2 times, most recently from a3fbe57 to f000062 Compare April 7, 2018 16:12
@snewcomer snewcomer requested a review from hhff April 7, 2018 20:43
Lastly, by default, ember-infinity expects the server response to contain something about how many total pages it can expect to fetch. `ember-infinity` defaults to looking for something like `meta: { total_pages: 20 }` in your response. See [Advanced Usage](#AdvancedUsage).


### Closure Actions<a name="ClosureActions"></a>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

README details

this.sendAction('loadPreviousAction', infinityModelContent, -1);
if (typeof(get(this, 'infinityLoad')) === 'function') {
// closure action
return get(this, 'infinityLoad')(infinityModelContent, -1);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

new api for infinity-loader

} else {
return true;
}
}
},

/**
@private
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

move all logic to service

@@ -33,6 +33,7 @@
"ember-cli-htmlbars": "^2.0.1",
"ember-cli-htmlbars-inline-precompile": "^1.0.0",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-mirage": "^0.4.3",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

add mirage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Haven't replaced all instances, but plan on fixing these over time.

@@ -0,0 +1,143 @@
import { module, test } from 'qunit';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

replace test (offset-trigger) with general acceptance test

{{infinity-loader
infinityModel=model
infinityLoad=(action loadMorePosts)
infinityLoadPrevious=(action loadMorePostsPrevious)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

examples using closure actions

infinityModel.replace(0, len, []);
return infinityModel;
}
},
Copy link
Collaborator Author

@snewcomer snewcomer Apr 7, 2018

Choose a reason for hiding this comment

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

replace, flush, pushObjects, unshiftObjects. Not sure about having the same API as Ember though for pushObjects/unshiftObjects. Thoughts?

@snewcomer snewcomer added enhancement and removed WIP labels Apr 8, 2018
};

let convertToArray = (queryObject) => {
if (queryObject.toArray) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could also add if not an array, but an object, then make an array

@snewcomer snewcomer merged commit 90b905f into master Apr 13, 2018
@snewcomer snewcomer deleted the sn/component-loading branch April 13, 2018 21:19
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

1 participant