-
Notifications
You must be signed in to change notification settings - Fork 200
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
New Method API #141
Comments
I favor the dot calls more than string accessors. |
Cool @LeviSchuck. I prefer them as well, and they will not be present in data anymore. I have a feeling that this change will be welcomed (I certainly like it), and am working on the changes right now. By the way, you can use functional components for a little speed boost (if you're writing custom render functions). The way functional components work is that they can have data, props, and inserts. This will only work for v1.0.0-pre-alpha. Moon.extend("Functional", {
functional: true,
data: () => ({
foo: "Local Data"
}),
props: ["bar"],
render: function(m, context) {
// Data AND props are available in `context.data`
// Insert is available in `context.insert`
return m("h1", {attrs: {}}, {dynamic: 1}, [
m("#text", {dynamic: 1}, `Local Data: ${context.data.foo} | Props: ${context.data.bar}`)
]);
}
}); |
Why is it that |
@trusktr It is possible, but that would mean you can't name methods as any of Moon's internal properties. |
I dig this. |
@trusktr @sudomabider If you really want them on the instance (and will be careful to name them correctly), then you will be able to use this in v1: const MoonMethods = {
init(Moon) {
const MoonInit = Moon.prototype.init;
Moon.prototype.init = function() {
const methods = this.methods;
for(let name in methods) {
this[name] = methods[name];
}
MoonInit.call(this);
}
}
};
Moon.use(MoonMethods);
const app = new Moon({
methods: {
foo() {
alert("Foo Called!");
}
}
});
app.foo(); |
What about checking against a blacklist of methods that are not allowed to
be defined by the component author, throwing an error if the author tries to define a backlisted method? Is that too much?
|
Moon v1 will be getting a new method API that uses actual method calls instead of
instance.callMethod()
. Here is what it will look like:m-on
because it cannot infer if you will be changing the methods. In v1, Moon will enforce that all methods are constant and cannot change.instance.data
, but instead will be stored ininstance.methods
. This means that you can have data and methods with the same name (although this is a bad practice).m-on
will attach event listeners for methods differently, and will only deoptimize if a dynamic parameter is passed (m-on:click="foo(dynamicProperty)"
)@rogierverbrugge @LeviSchuck @kokujin @trusktr @karlseguin I'd love to know your thoughts on this (you guys are pretty active on here).
The text was updated successfully, but these errors were encountered: