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

Выполнение скрипта после отрисовки блока #77

Closed
in19farkt opened this issue Jan 11, 2017 · 2 comments
Labels

Comments

@in19farkt
Copy link

in19farkt commented Jan 11, 2017

Привет.

Подключили Makeup к стартеркиту на вебпак. Для некоторых компонентов, после отрисовки, нужно выполнять скрипт, чтобы компонент принял окончательный внешний вид (используются jquery плагины). Можно ли среагировать на переключение элемента, чтобы после вставки элемента на страницу его проинициализировать?

Сейчас решили проблему так:

import pugTemplate from './index.pug';
import render from '../calendar';

const data = {
  name: 'calendar',
  type: 'module',
  items: [{
    name: 'default.calendar.component',
    type: 'module',
  }]
};

function template({module: blockName}) {
  switch (blockName) {
    case 'default.calendar.component': {
      setTimeout(() => {render()}, 300);
      return pugTemplate({});
    }
  }
}

export {
  data,
  template,
}

здесь функцию render() нужно выполнить после отрисовки блока default.calendar.component.

@Chaptykov
Copy link
Collaborator

Привет!

В объекте с данными вы можете для любого уровня вложенности указать поле snippet, значением которого должна быть функция.

После инициализации компонента, выполнятся все сниппеты по цепочке вложенности.

Например, для таких данных:

var data = {
  label: 'Project',
  snippet: () => console.log(1),
  items: [
    {
      name: 'component',
      snippet: () => console.log(2)
    }
  ]
}

После отрисовки блока, в консоли выведется:

1
2

@in19farkt
Copy link
Author

Спасибо :)

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

No branches or pull requests

2 participants