Creating a plugin in dative v2-alpha is different from the other versions
Since the Dative.use(plugin)
has deprecated
So We introduced a new way which also helps more
Let's Start Cooking :)
export let Profile = Dative.extend({
...,
use: [function({ instance, proto, Dative }: { instance: Dative, proto: Dative, Dative: typeof Dative }){
// Dative=> the Dative constructor
// instance=> the current instance of your application
// proto=> the Dative prototype
}]
})
Let's Create A Plugin
// src/plugins/my-plugin.js
export let MyPlugin = function({ instance, proto, Dative }){
// 1. Let's make a global property
Dative.defineProperty('appName',function(){
return 'Dative News'
})
// Now You Can Get the options of the instance
console.log(instance.options.me)
}
How do we use it ??
...
import { MyPlugin } from './plugins/my-plugin'
export let Profile = Dative.extend({
...,
use: [MyPlugin],
// we can now use the option we defined
me: "Holla" //=> Holla
})
Thanks For Reading
If You Have any Question About Dative
Feel free to ask me on twitter
Top comments (0)