DEV Community

Cover image for Creating a plugin in Dative v2-alpha
Tobi
Tobi

Posted on

Creating a plugin in Dative v2-alpha

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
  }]
})
Enter fullscreen mode Exit fullscreen mode

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)
}
Enter fullscreen mode Exit fullscreen mode

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
})
Enter fullscreen mode Exit fullscreen mode

Thanks For Reading

If You Have any Question About Dative

Feel free to ask me on twitter

Top comments (0)