Skip to content

Instantly share code, notes, and snippets.

@DavidSouther
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidSouther/3740fb0ba6ec2dc9e51b to your computer and use it in GitHub Desktop.
Save DavidSouther/3740fb0ba6ec2dc9e51b to your computer and use it in GitHub Desktop.
Musings on AtScript annotations with a Flux component.
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();
}
}
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 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 }}
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