Skip to content

Instantly share code, notes, and snippets.

@megatolya
Last active August 29, 2015 14:10
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 megatolya/98da2cf92286859f7194 to your computer and use it in GitHub Desktop.
Save megatolya/98da2cf92286859f7194 to your computer and use it in GitHub Desktop.
var App = Backbone.Model.extend({
defaults: {
headerText: 'hello world'
}
});
var app = new App;
var mybemjson = [{
block: 'b-page',
content: [{
block: 'checkbox',
bind: 'app',
attrs: {
disabled: function(app) {
return Boolean(app.get('headerText'));
}
}
}]
}];
var mybemjson = {
block: 'b-page',
content: {
block: 'list',
content: [
{block: 'item', content: 'Сделать что-то'},
{block: 'item', content: 'Сделать что-то еще'}
]
}
};
var App = Backbone.Model.extend({
defaults: {
headerText: 'hello world'
}
});
var app = new App;
var mybemjson = [{
block: 'b-page',
content: [{
block: 'header',
bind: 'app',
// меняется в зависимости от изменении `model`
content: function(app) {
return app.get('headerText');
}
}]
}];
BEM.DOM.decl(‘b-page’, {
onSetMod: {…},
showSettings: function() {},
showAdvertisement: function() {},
showAnotherShtonibut: function() {}
});
block: 'task',
iterate: 'task in tasks,',
bind: 'task',
content: function(task) {
var name = task.get('name');
if (task.get('done')) {
name += ' [done]';
}
return name;
},
onClick: function(event) {
task.set('done', true);
}
var Tasks = Backbone.Collection.extend();
var Task = Backbone.Model.extend({
initialize: function(text) {
this.set('name', text);
},
defaults: {
done: false
}
});
var tasks = new Tasks([
new Task('Сделать что-то'),
new Task('Сделать что-то еще'),
new Task('Сделать все остальное'),
new Task('Все переделать')
]);
var mybemjson = [{
block: 'b-page',
content: [{
block: 'list',
content: {
block: 'item',
iterate: 'task in tasks',
bind: 'task',
content: function(task) {
var name = task.get('name');
if (task.get('done')) {
name += ' [done]';
}
return name;
}
}
}]
}];
var App = Backbone.Model.extend({
defaults: {
headerText: 'hello world'
}
});
var app = new App;
var mybemjson = [{
block: 'b-page',
content: [{
block: 'checkbox',
bind: 'app',
mods: {
disabled: function(app) {
return !Boolean(app.get('headerText'));
}
}
}]
}];
var model = new Backbone.Model.extend();
var mybemjson = [{
block: 'b-page',
content: [{
block: 'header',
// меняется в зависимости от изменении `model`
content: function() {
return model.get('something');
}
}]
}];
// auth.js
channels(‘api’).on(‘authChanged’, function() {}});
channels(‘api’).on(‘backgroundChanged’, function() {});
BEM.DOM.decl(‘auth’, {...});
BEM.DOM.decl('task', {
onSetMod: {
js: function() {
this.bindTo('click', function() {
this.getModel().set('done', true);
});
}
},
getModel: function() {..}
});
// b-page.js
this.trigger('authChanged', authState);
// auth.js
BEM.blocks['b-page'].on('something-happened', doSomething);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment