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 characters
// Unique with use object | |
function uniqueObject(array) { | |
var hash = Object.create(null); | |
var result = []; | |
var value; | |
for (var i = 0; i < array.length; i++) { | |
value = array[i]; | |
if (!hash[value]) { | |
hash[value] = true; |
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 characters
var events = require('basis.event'); | |
var resolveValue = require('basis.data').resolveValue; | |
module.exports = function createBlockClass(BaseClass, ext) { | |
return BaseClass.subclass(ext, { | |
visible: true, | |
visibleRA_: null, | |
emit_visibleChanged: events.create('visibleChanged'), | |
// value could be a function or binding-bridge instance; any other converts to bool | |
setVisible: function(value) { |
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 characters
var csso = require('csso'); | |
function splitByScope(css) { | |
var scopes = {}; | |
csso.walk(csso.parse(css), function(node) { | |
if (node.type === 'Class') { | |
var className = node.name; | |
var scopeId = className.replace(/^([^_]+)_.+/, '$1'); // scopeId is block name |
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 characters
// react 0.14-rc1 | |
var Zoo = React.createClass({ | |
render: function() { | |
return <div>Giraffe name: <input ref="giraffe" /></div>; | |
}, | |
showName: function() { | |
// Previously: var input = this.refs.giraffe.getDOMNode(); | |
var input = this.refs.giraffe; | |
alert(input.value); | |
} |
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 characters
// doesn't work w/o this interface creation | |
require('readline').createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
// stop process input | |
process.stdin.pause(); | |
// read from stdin 10 times per second to check if ctrl+c pressed |
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 characters
var chalk = require('chalk'); | |
var readline = require('readline'); | |
var BAR_LENGTH = 40; | |
var lines = 0; | |
function repeatStr(str, len){ | |
return new Array(parseInt(len) + 1).join(str); | |
} | |
function drawBarLine(fill, str){ |
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 characters
// | |
// Enum class is proposed future citizen of basis.js | |
// | |
var Value = require('basis.data').Value; | |
var Enum = Value.subclass({ | |
className: 'Enum', | |
init: function(){ |
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 characters
function getRange(str, start, end){ | |
var lines = str | |
.split('\n') | |
.slice(start.line - 1, end.line); | |
return lines | |
.concat(lines.pop().substr(0, end.column)) | |
.join('\n') | |
.substr(start.column - 1); | |
} |
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 characters
// we could create several effects for node/models and don't affect node/models | |
var source = new basis.data.Dataset({ items: [/* .. */]}); | |
var modified = new basis.data.dataset.Filter({ | |
source: source, | |
ruleEvents: 'rollbackUpdate', | |
rule: 'data.modified' | |
}); | |
var customSet = new basis.data.Dataset(); | |
var view = new basis.ui.Node({ |
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 characters
// create element with color green | |
var elem = document.createElement('div'); | |
elem.style.color = 'green'; | |
document.body.appendChild(elem); // add to document, to make getComputedStyle/animate works | |
console.log(getComputedStyle(elem).color); // rgb(0, 128, 0) - it's OK! | |
// add animation | |
var player = elem.animate([ | |
{ color: 'red' }, | |
{ color: 'blue' } |