Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first/last/nth-child patch for after/before emulation #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

smelukov
Copy link
Member

No description provided.

Sergey Melyukov added 3 commits September 7, 2016 17:54
// todo возможно есть более простой способ сфлэтить все селекторы из ast
walk(sourceAst, {
SimpleSelector: function(token) {
token.sequence.each(function(part) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

token.sequence.toArray()

Copy link
Member

@lahmatiy lahmatiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пробежался по диагонали

},
childClass: {
template: resource('./template/variant.tmpl'),
init: function() {
Node.prototype.init.call(this);

// копируем объект и сортируем его свойства
this.condition = sortObject(basis.object.merge(this.condition));
this.states = sortObject(basis.object.merge(this.states));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем merge для одного объекта? лучше slice если нужна копия

var firstToken = token.sequence.head;

if (firstToken.data.type == 'Class' && firstToken.data.name == this.wrapperClass) {
token.sequence.remove(token.sequence.first());
Copy link
Member

@lahmatiy lahmatiy Sep 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если sequence это инстанс List, то тут не будет удаления (вернее будет что-то странное) и нужно .first() -> .head

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap не проверял
надо глянуть )

walk(resource.AST, {
SimpleSelector: function(token, parent) {
token.sequence.each(function(part) {
var emulators = getAllEmulators(this.emulators);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а точно нужно вычислять для каждого новый emulators?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нет )

this.template = this.generator.generate(this.states);
this.wrapperClass = 'dp-variant-wrapper-' + this.basisObjectId;
this.resources = this.resources.map(function(resource) {
return new ProcessableStyleResource({source: resource, useImmediate: true});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пробельчики бы для литеральных объектов { source: .., useImmediate: true }

@@ -59,7 +72,9 @@ module.exports = function pseudoElementFactory(type, before) {

mapper.removeSelector(token);
allowToEmulate.forEach(function(element) {
var existingEmulator = element.querySelector(TYPE_NAME);
var existingEmulator = basis.array.from(element.children).filter(function(child) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basis.array.find(..., function(child) {
  return child.tagName.toLowerCase() == TYPE_NAME.toLowerCase();
})

var states = [];
var state = {};

state[type] = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module.exports = function pseudoClassFactory(type) {
  var TYPE_NAME = 'pseudo-class-' + type + '__' + basis.genUID();
  var typeState = basis.fn.wrapper(type);
...
  var states = [typeState(false), typeState(true)];

// пропускаем псевдо классы/элементы, иначе querySelectorAll не найдет узлы
if (sourcePart.type != 'PseudoClass' && sourcePart.type != 'PseudoElement') {
if ((sourcePart.type != 'PseudoClass' || sourcePart.type == 'PseudoClass' && sourcePart.name == 'first-element') && sourcePart.type != 'PseudoElement') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

очень странное место )
переделаю

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants