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

Expose immediate type and clear as semi-private API #8

Closed
wants to merge 1 commit into from

Conversation

blackxored
Copy link

Adding the ability to bypass the queue system for advanced animations, particular case when you have two elements in the page that you want to sync, I couldn't find another way.

      const postTyper = malarkey(postEl, typerOptions);
      const receiveTyper = malarkey(receiveEl, {...typerOptions, loop: false});

      scope.vm.headlines.forEach((phrase) => {
        postTyper
          .call(function(el) {
            el.classList.add('has-cursor');
            this();
          })
          .type(phrase.post)
          .call(function(el) {
            el.classList.remove('has-cursor');
            receiveEl.classList.add('has-cursor');
            const self = this;
            receiveTyper._type(function() {
              self();
            }, phrase.receive, typerOptions.typeSpeed);
          })
          .pause(1000)
          .call(function() {
            [postEl, receiveEl].forEach(elem => elem.classList.add('highlighted'));
            this();
          })
          .pause(1000)
          .call(function() {
            const self = this;
            [postEl, receiveEl].forEach(elem => {
              elem.classList.remove('highlighted')
              elem.classList.remove('has-cursor');
            });
            receiveTyper._clear(function() {
              self();
            });
          })
          .clear()

@yuanqing
Copy link
Owner

yuanqing commented Jan 7, 2016

@blackxored Am wondering if there's a cleaner way. Can you post a runnable example (JSFiddle, or other) so that I can better understand the effect you're after?

@blackxored
Copy link
Author

I'm not really sure if I can re-create something without involving (more) private code :D. The desired effect is to have two elements that are enhanced by this plugin on the page. In my snippet postTyper and receiverTyper, first you type something into postTyper, then type something with receiveTyper, then highlighted and delete, basically I needed to bypass the queue to make them sync (postTyper stops until receiveTyper is finished typing, and so on). Hopefully makes sense.

@yuanqing
Copy link
Owner

@blackxored

Just cut a release (1.3.3) that fixes a bug in the internal enqueue method: 3fd1786

With the fix, we can achieve the effect you’re after using only the public APIs. See this JSFiddle. Just know that it’s not perfect, though: the internal function queue of one of the elements (namely yElem) is “unbounded” — meaning, we keep on adding functions to it. This module was not designed to work with this sort of complex use case.

@blackxored
Copy link
Author

I'll take a look and I'll let you know.

@yuanqing yuanqing closed this Mar 20, 2018
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.

None yet

2 participants