Plugin updating page variables with setState?

Hi guys,
I will try to be as clear as possible in my question, but I apologize if my English is not very good.

I created a plugin following the tips in this link: https://framework7.io/docs/plugins-api.html

This plugin receives a notification via OneSignal, and the idea is that I can manipulate my page variables dynamically, using setstate (), and here comes the difficulty.

However, I would like to know if it is possible for this plugin to change a variable via setstate () of the current page I am on.

To make it clearer, I am placing my PLUGIN.

window.notifyPusher = {
  name: 'notifyPusher',  
  params: {
    onesignalKeyAndroid: "XXXXXXXX",
    onesignalCallback: {},
  },
  create: function () {
    var app = this;

    app.params.onesignalCallback = function(jsonData) {         
      
      if(jsonData.hasOwnProperty("notification")){
        var additionalData = jsonData.notification.payload.additionalData;
      }else{
        var additionalData = jsonData.payload.additionalData;
      }
            /// JUST HERE I NEED CHANTE VARIABLES ON PAGE ACTIVE
    };
  },
  on: {
    init: function () {
      var app = this;

      window.plugins.OneSignal
        .startInit((app.device.ios == "ios" ? app.params.onesignalKeyIOS : app.params.onesignalKeyAndroid))
        .handleNotificationReceived(app.params.onesignalCallback)
        .endInit(); 

      window.plugins.OneSignal
        .startInit((app.device.ios == "ios" ? app.params.onesignalKeyIOS : app.params.onesignalKeyAndroid))
        .handleNotificationOpened(app.params.onesignalCallback)
        .endInit();      

      window.plugins.OneSignal.getPermissionSubscriptionState(function(status) {            
        console.log(status);
        var idapp = status.subscriptionStatus.userId;
        localStorage.setItem('device-push-id',idapp);
      });
    },    
    pageInit: function (page) {
      console.log("PAGEINIT",page);
    },    
  }
}

And below is my page, I don’t need to update the requestUser variable requestUser…

<script>
	return {
		data: function () {
			return {
				intervalSyncLoc: null,
				statusMe: false,
				requestUser: null,
			}
		},
[....]

Is this possible?

Hi guys!!!

I managed to solve my problem, maybe it is not the most correct way, but I will put my solution below .

As I mentioned, I created a plugin to listen to the notifications and then perform some action.
Thus, in my plugin I created the pageInit and pageReInit methods, that is, every time a page is accessed I can manipulate the component, and for that I put the excerpt below.

var pageComponent = page.router.currentPageEl.f7Component;
pageComponent.myMethodUniqueInsidePage();
//or
pageComponent.$setState({ variable: 1 });
1 Like