These are chat archives for reactioncommerce/reaction

20th
Jul 2016
Paul Grever
@paulgrever
Jul 20 2016 16:49

so working on some methods in imports/plugins/getoutfitted/lib/api as we switch our packages to plugins. And while in common, I was wondering which Reaction to import. I see two options of:
import { Reaction } from "/client/api”;
import { Reaction } from "/server/api”;

is there a common reaction that can be accessed on both?

Mike Murray
@mikemurray
Jul 20 2016 17:20
@paulgrever no, If you want to use both on come common area, you can try conditional imports.
Jeremy Shimko
@jshimko
Jul 20 2016 17:52
Spencer Norman
@spencern
Jul 20 2016 17:54
Would you recommend using require instead of import globally or just when nested?
Jeremy Shimko
@jshimko
Jul 20 2016 17:54
just when nested.
Spencer Norman
@spencern
Jul 20 2016 17:54
:+1:
Jeremy Shimko
@jshimko
Jul 20 2016 17:56
The ;tldr on that article is nested imports depend on Meteor's custom ES6 compiler (instead of Babel). If you ever try to use that code outside of the Meteor build tool context, it won't work.
So probably something like this (not tested):
let Reaction;

if (Meteor.isClient) {
  Reaction = require('/client/api').Reaction;
} else {
  Reaction = require('/server/api').Reaction;
}
Spencer Norman
@spencern
Jul 20 2016 17:56
saw that, good call on require
Jeremy Shimko
@jshimko
Jul 20 2016 17:57
What do you need it for though? We managed to completely avoid it in the entire app, so I'm wondering if there's a workaround I might be able to suggest.
Spencer Norman
@spencern
Jul 20 2016 17:57
I don’t think we will end up needing it, looks like a candidate for a better server/client refactor, but the question came up
Jeremy Shimko
@jshimko
Jul 20 2016 17:57
ah

Most (all?) of the isomorphic stuff should be able to be imported from the common code in /lib. Like collections, for example.

import { Carts, Shops } from '/lib/collections';

instead of Reaction.Collections(which also works)

Spencer Norman
@spencern
Jul 20 2016 18:00
That’s really helpful
Jeremy Shimko
@jshimko
Jul 20 2016 18:03

There are only a few older Reaction.something methods that needed to be isomorphic. getShopId was one of them. That said, there are a handful of methods available at /lib/api that can be imported in common code.

import { getShopId } from '/lib/api';

Reaction.getShopId() === getShopId() (but getShopId() is isomorphic and can be imported in common code)

which can all be imported from /lib/api
Paul Grever
@paulgrever
Jul 20 2016 18:46
@jshimko that’s exactly what I was using it for… and I found the {getShopId }