Last active
August 29, 2015 14:13
-
-
Save DavidSouther/3740fb0ba6ec2dc9e51b to your computer and use it in GitHub Desktop.
Musings on AtScript annotations with a Flux component.
This file contains 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 characters
import {Component} from 'angular' | |
import {template} from 'chat/message/item-template'; | |
@Inject(['ChatActions', 'MessageStore']) | |
@Component({selector: 'messageItem', bindAs: 'state', template: template}) | |
@IsolateScope({query: 'query'}) | |
export class MessageItem { | |
constructor(Actions: ChatActions, Store: MessageStore}) { | |
this._Actions = Actions; | |
this._Store = Store; | |
this._Store.on(this._Store.Events.updated, (data)=> this.update(data)); | |
update(this._Store.messages); | |
} | |
update(data) { | |
this.messages = data.slice(); | |
} | |
sendMessage(text){ | |
(new this._Actions.SendMessage( | |
text, new Date() | |
)).dispatch(); | |
} | |
} |
This file contains 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 characters
describe('MessageItem', function(){ | |
var sut = null; | |
describe('Behaviors', function(){ | |
import {MockMessages} from '../messages/mocks'; | |
import {Actions} from '../actions'; | |
function InstantiateComponent(){ | |
import {MessageItem} from './item-component'; | |
sut = new MessageItem(Actions, MockMessages)); | |
} | |
beforeEach(InstantiateComponent); | |
it('load message from the store', function(){ | |
sut.messages.length.should.equal(MockMessages.messages.length); | |
}); | |
}); | |
describe('Rendering', function(){ | |
import {MockMessages} from '../messages/mocks'; | |
}); | |
}); |
This file contains 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 characters
//- This will be compiled | |
div | |
div.col-md-2 | |
form | |
label(for="search") Search | |
input.form-control(name="search", ng-model="state.query") | |
div.col-md-10 | |
ol.messages | |
li.message(ng-repeat=" message in state.messages | filter:state.query ") | |
span.when {{ message.date | date:'medium' }} | |
div {{ message.text }} |
This file contains 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 characters
export template = '<div><div class="col-md-2">...ng-model="state.query"...</div>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment