Last active
November 30, 2018 02:48
Revisions
-
1276stella revised this gist
Nov 30, 2018 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,9 @@ export default Ember.Component.extend({ console.log('currentCardIndex', currentCardIndex); console.log('items', items); if (!items || items.length === 0 || currentCardIndex >= items.length) { return; } return items[currentCardIndex]; }), @@ -28,7 +30,7 @@ export default Ember.Component.extend({ if (items.length > 1 && currentCardIndex === items.length - 1) { this.decrementProperty('currentCardIndex'); } items.removeAt(currentCardIndex); } }, -
1276stella revised this gist
Nov 28, 2018 . 1 changed file with 10 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,26 +6,28 @@ export default Ember.Component.extend({ currentCard: Ember.computed('currentCardIndex', 'items.length', function getCurrentCard() { const items = this.get('items'); const currentCardIndex = this.get('currentCardIndex'); console.log('currentCardIndex', currentCardIndex); console.log('items', items); return items[currentCardIndex]; }), actions: { nextCard() { this.set('currentCardIndex', this._getNextCard()); }, prevCard() { this.set('currentCardIndex', this._getPrevCard()); }, removeCard() { const items = this.get('items'); const currentCardIndex = this.get('currentCardIndex'); if (items.length > 1 && currentCardIndex === items.length - 1) { this.decrementProperty('currentCardIndex'); } this.get("items").removeAt(currentCardIndex); } }, -
1276stella revised this gist
Nov 28, 2018 . 3 changed files with 21 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,8 +3,13 @@ import Ember from 'ember'; export default Ember.Component.extend({ currentCardIndex: 0, currentCard: Ember.computed('currentCardIndex', 'items.length', function getCurrentCard() { const items = this.get('items'); const currentCardIndex = this.get('currentCardIndex'); if (!items || currentCardIndex >= items.length) { return; } return items[currentCardIndex]; }), actions: { @@ -15,7 +20,14 @@ export default Ember.Component.extend({ prevCard() { console.log('prev'); this.set('currentCardIndex', this._getPrevCard()); }, removeCard() { console.log() const currentCardIndex = this.get('currentCardIndex'); console.log('items', this.get("items")); console.log('currentCardIndex', currentCardIndex); this.get("items").removeAt(currentCardIndex); } }, _getNextCard() { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,10 +2,12 @@ {{#collection-carousel items=cards as |card prevCard nextCard removeCard| }} {{card.title}} {{card.subtitle}} <br> <button {{action prevCard}}>Prev</button> <button {{action nextCard}}>Next</button> <button {{action removeCard}}>Dismiss</button> {{/collection-carousel}} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ {{yield currentCard (action "prevCard") (action "nextCard") (action "removeCard") }} -
1276stella created this gist
Nov 22, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ import Ember from 'ember'; export default Ember.Component.extend({ currentCardIndex: 0, currentCard: Ember.computed('currentCardIndex', function getCurrentCard() { return this.get('items')[this.get('currentCardIndex')]; }), actions: { nextCard() { console.log('next'); this.set('currentCardIndex', this._getNextCard()); }, prevCard() { console.log('prev'); this.set('currentCardIndex', this._getPrevCard()); }, }, _getNextCard() { const maxIndex = this.get('items.length'); const currentCardIndex = this.get('currentCardIndex'); return (currentCardIndex + 1) % maxIndex; }, _getPrevCard() { const maxIndex = this.get('items.length'); const currentCardIndex = this.get('currentCardIndex'); return (currentCardIndex + maxIndex - 1) % maxIndex; } }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import Ember from 'ember'; export default Ember.Controller.extend({ appName: 'Ember Twiddle', init() { this.set('cards', [ { title: 'Card 1', subtitle: 'Composition in Ember is great', }, { title: 'Card 2', subtitle: 'It makes components small and reusable', }, { title: 'Card 3', subtitle: 'Not sure...', } ]); } }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <h1>Welcome to {{appName}}</h1> {{#collection-carousel items=cards as |card prevCard nextCard| }} {{card.title}} {{card.subtitle}} <button {{action prevCard}}>Prev</button> <button {{action nextCard}}>Next</button> {{/collection-carousel}} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ {{yield currentCard (action "prevCard") (action "nextCard") }} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ { "version": "0.15.1", "EmberENV": { "FEATURES": {} }, "options": { "use_pods": false, "enable-testing": false }, "dependencies": { "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", "ember": "3.4.3", "ember-template-compiler": "3.4.3", "ember-testing": "3.4.3" }, "addons": { "ember-data": "3.4.2" } }