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

Define available callbacks for events used as directives #40

Open
paleo opened this issue Dec 12, 2016 · 9 comments
Open

Define available callbacks for events used as directives #40

paleo opened this issue Dec 12, 2016 · 9 comments

Comments

@paleo
Copy link

paleo commented Dec 12, 2016

Hi, thanks for this amazing template engine. Here is a suggestion.

I currently use events with this kind of code:

<input type="text" :onchange="{{ ctrl.changeText }}">

import Template from './Template.monk';
let state = {
  someStateVariable: 'abc',
  ctrl: {
    changeText: e => { /* ... */ }
  }
}
view = Monkberry.render(Template, el, {
  directives: { /* ... */ }
})
view.update(state)

I would like to configure available callbacks the same way as for directives:

import Template from './Template.monk';
let state = {
  someStateVariable: 'abc'
}
view = Monkberry.render(Template, el, {
  directives: { /* ... */},
  callacks: {
    changeText: e => { /* ... */ }
  }
})
view.update(state)

I prefer to not extend the template class. I just need to define available callbacks, like methods in Vue.


NB: Personally, I would prefer to use the delegating way. But I can't, because the selector is applied after the rendering of directives. I have sub-components included by directives. The following code interferes with DOM nodes of the sub-components:

view.on('click', 'div', (event) => { ... });

IMO the selector should be applied before to render the directives.

@antonmedv
Copy link
Owner

So you proposing to add methods? Like this:

Monkberry.render(Template, el, {methods:
  callback: () => {...}
});

@paleo
Copy link
Author

paleo commented Dec 13, 2016

Yes, but I'm unsure that "methods" is the right term. A method is in the context of the OOP. But it is precisely in order to avoid OOP that I need this feature. If callbacks is not correct, maybe "functions"? Or "procedures"?

Or perhaps we can consider it is a way to provide methods of the template (the template is like an instance), but IMO it's not the proper term because we don't use this to call them.

@antonmedv
Copy link
Owner

callbacks?

@paleo
Copy link
Author

paleo commented Dec 13, 2016

It is my first proposition. A callback is:

In computer programming, a callback is a piece of executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at some convenient time.

We can consider that we pass a list of callbacks as arguments to the code of the template, which we expect that they will be called back at some convenient time. It seems OK.

It depends on which is the syntax in the template, too. For example, we want to define a callback named onChangeText. In the template, which syntax have we to use?

<input type="text" :onchange="{{ onChangeText }}">

or with a prefix (if we need a prefix, then I suggest controller)?

<input type="text" :onchange="{{ controller.onChangeText }}">

Without a prefix, a callbacks option seems a good term:

Monkberry.render(Template, el, {
  callbacks: {
    onChangeText: (event) => {...}
  }
});

However, if the syntax requires a prefix, then I think it would be better to use the same prefix in options:

Monkberry.render(Template, el, {
  controller: {
    onChangeText: (event) => {...}
  }
});

@antonmedv
Copy link
Owner

Maybe allow to use or not prefixes?

Monkberry.render(Template, el, {
  callbacks: {
    controller: {
       onChangeText: (event) => {...}
    }
  }
});

@paleo
Copy link
Author

paleo commented Dec 14, 2016

I'd like that!

@antonmedv
Copy link
Owner

Will try to implement it in next release.

@paleo
Copy link
Author

paleo commented Sep 3, 2017

Hello, is there a date scheduled for the release of this feature?

@antonmedv
Copy link
Owner

Hi,
I haven't time for scheduled work on this project any more. But I have plans on releasing new major version v5, but again – I don't know when.
If you, or somebody else wants to become a maintainer – your're welcome.

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

No branches or pull requests

2 participants