Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
nativescript-observable-subscribe
Advanced tools
A NativeScript module to add subscribe functionality to observables
NativeScript module that adds subscribe support to observables. Listening for observable changes can always be done using standard addEventListener technique that can be found in the NativeScript docs, but this is a much more convenient subscription method that keeps your code neat by isolating handlers for individual properties. As NativeScript is constantly evolving, a subscribe solution might be implemented in the core project as a tns module making this module obsolete; so one should keep an eye out for that.
Run npm install nativescript-observable-subscribe --save
from your project's app
directory:
.
├── app <------------------------------ run npm install from here
│ ├── app.css
│ ├── app.js
│ ├── bootstrap.js
│ ├── main-page.js
│ ├── main-page.xml
│ ├── node_modules
│ │ └── nativescript-observable-subscribe <-- The install will place the module's code here
│ │ └── ...
│ └── package.json <----------------- The install will register “nativescript-observable-subscribe” as a dependency here
│ └── tns_modules
│ └── ...
└── platforms
├── android
└── ios
If npm doesn't end up working for you, you can just copy and paste this repo's observablesubscribe.js file into your app and reference it directly.
To use the Observable Subscribe Module you must first require()
it from your project's node_modules
directory:
require( "./node_modules/nativescript-observable-subscribe/observablesubscribe" );
Once you have required the module in your code, it will execute and add the subscribe/unsubscribe functions to observable. You will be able to start using it to get notified of property changes like this:
// viewmodel.js
...
var mainViewModel = new HelloWorldModel();
var counterPropName = 'counter';
mainViewModel.subscribe(counterPropName, function(args){
if (this.get(counterPropName) <= 0) {
this.set(messagePropName, "Hoorraaay! You unlocked the NativeScript clicker achievement!");
}
else {
this.set(messagePropName, this.get(counterPropName) + " taps left");
}
}, mainViewModel);
exports.mainViewModel = mainViewModel;
If you want to unsubscribe a property from notifications, you can use the unsubscribe function like this:
// viewmodel.js
...
mainViewModel.unsubscribe(counterPropName, callback);
...
*Thanks to TJ VanToll for the directory structure graphic above and the template for this doc
FAQs
A NativeScript module to add subscribe functionality to observables
We found that nativescript-observable-subscribe demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.