Giter Club home page Giter Club logo

nativescript-globalevents's Introduction

npm npm npm

nativescript-globalevents

A NativeScript plugin to deal with Global events

License

This is released under the MIT License, meaning you are free to include this in any type of program -- However for entities that need a support contract, changes, enhancements and/or a commercial license please contact me at http://nativescript.tools.

I also do contract work; so if you have a module you want built for NativeScript (or any other software projects) feel free to contact me [email protected].

Donate Patreon

Installation

tns plugin add nativescript-globalevents

Usage

To use the module you just require() it:

require( "nativescript-globalevents" );

Notice: You do NOT need to keep a reference to it; and you only need to load it once.

It will automatically attach its methods to all the proper classes in the NativeScript library making it act as if they are built in.

What this does is automatically add support to allow you to setup events on all the page events globally. For example; if you need a pageLoaded event to occur on every page; you can use this library to get a global pageLoaded event.

Events currently on the Page globally that are supported are:

  • Page.navigatingToEvent
  • Page.navigatedToEvent
  • Page.navigatingFromEvent
  • Page.navigatedFromEvent
  • Page.shownModallyEvent
  • Page.showingModallyEvent
  • View.loadedEvent
  • View.unloadedEvent

If you have any other global events you would like supported please open an issue on the github issue tracker and I will investigate its relevance.

You ask, how exactly does this help?

Well, my usage is I have several plugins that need to be notified when a new page is loaded/unloaded to allow custom handling to occur automatically. It could be useful for your own app if you need to do something globally when every page is loaded or unloaded.

require('nativescript-globalevents'); // need only once in the application total

var Page = require('ui/page').Page;
Page.on(Page.navigatingToEvent, function() { console.log("We have navigated to a new page!"); });

Why use this?

If you need to track globally an event and you don't want to put a handler in each separate page.xml/page.js file.

Commands and functions

Static Page class now has four new STATIC functions

Page.on / Page.addEventHandler (eventName, callback[, thisArg])
Page.off / Page.removeEventHandler (eventName[[, callback], thisArg])

Notes:

If thisArg is null/undefined it will use the current page's "this".

If callback is null on the off/removePageHandler it will remove ALL handlers.

nativescript-globalevents's People

Contributors

nathanaela avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.