Where to put the business logic of a Chrome extension - reactjs

I am developing my first Chrome extension and have a question related to where to put the main logic (and things like API calls).
I use React for the popup, so an option is to put all logic in these React components. This is what I would do if was making a normal web app.
But with extensions you also have background scripts. So if I for example have to implement OAuth logging-in logic, what is the best place to put all the code?

A simple logic: All the API calls should be done in background script and DOM manipulation in content script.

Related

Deep Linking in React without React-Native or React-Navigation

I have a request from a client to implement deep linking in our React application whereby clicking a link will take them directly into the installed app (potentially to a certain point but not sure on that yet).
To my understanding react-native and react-navigation both handle this as part of a feature set within "Linking" that they offer. However it seems excessive to import a framework just for deep linking (perhaps not though).
After googling I can only really find references to deep linking on react-native or react-navigation.
What is my best course of action?
Let's get to some basics first, then it will be clear.
In modern SPA's, say with React, it's common for the SPA to handle navigation itself. You need to use browser's history API. It's because your SPA is just a single index.html with bunch of js code, so it sort of virtual, every page is constructed by your app. In order to not reinvent a wheel, its easier to use some library for that, say react-router-dom.
But then everything works as expected, and you have deployed your app. When user wants to get some deep page, say, https://my-awesome-app.com/deep/page/1, browser will just send a request to a server, asking: "Please, server, give me a page 1.html, in folder page, in folder deep". But server doesn't have that file, because it has literally one index.html, because its a SPA application. Then we need to tell the server to re-write all deep routes to index html, here is an example for my app hosted on Netlify:
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
When user will ask for that page, server will 'redirect' that request to the index.html and my react-router-dom will figure out which 'PageComponent' to render based on that path.
So, you can implement routing in your app yourself, probably using browser's History API, but I guess it might be easier to use library. But it's your call.
On the other hand if your app is not an SPA, the story might be different, because say in NextJS routing is implemented in framework itself, and if used deep linking would require different setup depending on how app is deployed.
Deep-linking is handled largely by Apple and Google server-side
https://www.adjust.com/blog/dive-into-deeplinking/
React-native provides extended functionality for deep-linking within mobile apps but normal web-applications there is no need to implement it there. Use universal links or Google specific links as standard linking within your web app to enable deep linking

Using Vue or React in Amazon MTurk's HTMLQuestion

I want to create an MTurk HTML question that uses a modern web framework, such as Vue or React. For a minute let's assume I can't use an ExternalQuestion which just points to a website I create, but rather want to use HTMLQuestion.
Is that doable? Can I include React, for example, and it will work? Amazon's surrounding HTML will not interfere with it?
Yes, you can do this. Both HTMLQuestion and ExternalQuestion are rendered in an iframe when a worker accepts your HIT. As such, they're completely isolated from any other scripts or libraries on the surrounding page.

Can babylonjs communicate with a REST endpoint?

I am trying to develop a 3D UI with babylon. This UI is expected to communicate with some ReST endpoints. Basically clicking on certain points of the scene should make some ReST calls like get, post, put etc and accordingly some more sub scenes be displayed. Any leads to simple examples would be appreciated.
Sure, although I'd say that the two aren't really related. BabylonJS is the graphics library which allows you interact with Canvas and WebGL via JavaScript. Separately there are plenty of options to make REST requests via vanilla JavaScript (see here). So you'd be using JavaScript to code both your graphics and the REST requests. The way in which you combine the two is up to you!
Maybe start looking at https://doc.babylonjs.com/how_to/how_to_use_actions. That suggests you can hook up any JS code (your REST request for example) based on a trigger action.

reactjs with .jsp html templates

This is more of question of if it makes sense to use Reactjs in my instance. I have an application that generates html serverside. I can not use any js based templating solutions serverside, it is a java/jsp solution blackbox.
Since the markup is already defined I am weary of using JSX to duplicate all the template logic currently only on the serverside. What is typically the best approach to integrating reactjs in to an application like this.
What will be the real advantage to using reactjs for me in this situation. Most of may app will continue to be rendered serverside go forward.
Obviously React is not designed to be used like this; but you could still do it.
Long story short: If you want to build something more complex in front-end you should do it; if you only want to get advantage of JSX templating instead of jsp, it's just a big overhead.
Advantages:
You will be able to step away from standard jQuery approach of handling javascript in .jsp.
You will get all the benefit of a client-side framework, so you are able to handle more complex scenarios in front-end as you would do with standard javascript.
You could hide some business logic in the java side (servlets) and making it available to React world.
Disadvantages:
Probably it's a pain to prepare the development environment mode (webpack, hot-reload, etc.); e.g. you'll need to recompile the jsp on the fly on every js change.
You can't use client-side routing (so you'll have like one SPA per page).
Probably it's really hard to make server side rendering work (for the React part)

ExtJS Application launch on demand - not page load

I have a bundle of older ExtJs components that drive the UI, store management, and application logic in something that prior to the world of MVC I'd have called an application. I'm in the process of rewriting it, and wanted to take advantage of ExtJS MVC if possible.
The one thing that makes this unique from the tons of guides I'd otherwise be working from is that my Ext app doesn't own the whole page - instead of a full page viewport onready I have a modal Ext.window.Window that runs on an event from other non-ext javascript on the page.
I'd like to migrate this into a coherent ext application if possible, but as they seem to only properly launch when ext is ready I'm questioning if this is the right tool for the job.
My leading idea right now is to initialize the application on page load, but not actually render any views - exposing a static method on the app the external js can call to render and start my app's lifecycle on demand. Is this a good idea? Is there a better option I'm missing?
Yes, it is a very good idea. I have written an example of simple login system where the application is not actually started before the user logs-in.
It is very similar to your way in that that there is a method you call to actually start the app.

Resources