Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require RN packages #1

Closed
artemyarulin opened this issue Jan 3, 2016 · 3 comments
Closed

Require RN packages #1

artemyarulin opened this issue Jan 3, 2016 · 3 comments

Comments

@artemyarulin
Copy link
Owner

According to http://blog.fikesfarm.com/posts/2015-07-24-using-react-native-components-in-clojurescript.html RN packager resolve all require('package-name') by using their own custom logic. As we are using Figwheel and basically avoid packager we cannot just require a package which is a pain.

Idea: We specify all needed packages in src/repl.cljs like:

(ns repl.repl
  (:require [ktoa.repl :refer [start-repl]]))

(start-repl {:app-name "QwertyApp"
             :base-url "http://localhost:3449/js"
             :root-ns  "qwert.core"
             :packages ["react-native" 
                        "react-native-swiper"
                        "react-native-linear-gradient"]})

As our REPL app runs using RN packager we can require all of those packages and store it inside global ktoa.repl.packages

Later on in the main application code we may call ktoa.core.require('package-name') which in the development mode will fetch deps from the ktoa.repl.packages and during the release will emit simple require calls, which in turn will be processed during bundle creation.

@artemyarulin
Copy link
Owner Author

Better ide from the referenced re-natal discussion:

Can we wrap js/require function in the dev mode and return the package from the stored global var instead? This will make code cleaner without any ktoa.repl.require just simple js/require

@artemyarulin
Copy link
Owner Author

Addition to that - we cannot do things like

(let [packages ["react-native"])
  (zipmap packages (map js/require packages)))

As it looks like React packager use RegExp or not smart enough to catch it. Macroses FTW then!

@artemyarulin
Copy link
Owner Author

A bit of comments for the future references.

Although window.require is a function, the problem is that packager transforms all the module names and replaces it with some kind of paths, and using Fighweel we avoid the packager.

Another tricky thing that those replacing are quite hacky and for example you cannot make a require call from the nested scopes (see Conditional require with RN Packager)

How we can improve it:
1 Parse package.json and automatically require those? Hacky and not reliable
2 Before the eval of a module we can make a but of replacements. But we somehow need to tell the packager to load the module first
3 Move to boot-react-native and it's concept of relaying on react packager

Let's leave it as it - if any problem arise, it will a good sign to finally make a transition to boot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant