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

yield from the template #72

Merged
merged 1 commit into from Sep 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ you can work on its appearance.

By default, the `infinity-loader` will just output a `span` showing its status.

* **Providing a block**

```html
{{#infinity-loader infinityModel=model}}
<img src="loading-spinner.gif" />
{{/infinity-loader}}
```

If you provide a block to the component, it will render the block instead of
rendering `loadingText` or `loadedText`. This will allow you to provide your
own custom markup or styling for the loading state.

* **reached-infinity Class Name**

```scss
Expand Down
11 changes: 10 additions & 1 deletion addon/components/infinity-loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Ember from 'ember';
import emberVersionIs from 'ember-version-is';

export default Ember.Component.extend({
const InfinityLoaderComponent = Ember.Component.extend({
classNames: ["infinity-loader"],
classNameBindings: ["infinityModel.reachedInfinity"],
guid: null,
Expand Down Expand Up @@ -77,3 +78,11 @@ export default Ember.Component.extend({
Ember.run.scheduleOnce('afterRender', this, this._checkIfInView);
})
});

if (emberVersionIs('lessThan', '1.13.0')) {
InfinityLoaderComponent.reopen({
hasBlock: Ember.computed.alias('template')
});
}

export default InfinityLoaderComponent;
10 changes: 7 additions & 3 deletions app/templates/components/infinity-loader.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{{#if infinityModel.reachedInfinity}}
<span>{{loadedText}}</span>
{{#if hasBlock}}
{{yield}}
{{else}}
<span>{{loadingText}}</span>
{{#if infinityModel.reachedInfinity}}
<span>{{loadedText}}</span>
{{else}}
<span>{{loadingText}}</span>
{{/if}}
{{/if}}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{{#if infinityModel.reachedInfinity}}
<span>{{loadedText}}</span>
{{#if hasBlock}}
{{yield}}
{{else}}
<span>{{loadingText}}</span>
{{#if infinityModel.reachedInfinity}}
<span>{{loadedText}}</span>
{{else}}
<span>{{loadingText}}</span>
{{/if}}
{{/if}}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "^1.0.1",
"ember-cli-github-pages": "0.0.6",
"ember-cli-htmlbars-inline-precompile": "0.2.0",
"ember-cli-ic-ajax": "0.2.1",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-pretender": "0.3.2",
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/infinity-loader-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import hbs from 'htmlbars-inline-precompile';
import { test, moduleForComponent } from 'ember-qunit';

moduleForComponent('infinity-loader', {
integration: true
});

test('it renders loading text if no block given', function(assert) {
assert.expect(1);
this.on('infinityLoad', function () {});
this.render(hbs`
{{infinity-loader}}
`);
assert.equal(this.$('.infinity-loader > span').text(), "Loading Infinite Model...");
});

test('it yields to the block if given', function(assert) {
assert.expect(1);
this.on('infinityLoad', function () {});
this.render(hbs`
{{#infinity-loader}}
<span>My custom block</span>
{{/infinity-loader}}
`);
assert.equal(this.$('.infinity-loader > span').text(), "My custom block");
});