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

React Native support #38

Open
codingstyle opened this issue Jan 21, 2021 · 1 comment
Open

React Native support #38

codingstyle opened this issue Jan 21, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@codingstyle
Copy link

I am currently integrating the SDK in a React Native app written mainly with TypeScript.
So far Swell JS SDK works well, there are only two blocking issues:

  1. Buffer has to be set as a global variable to that SDK works correctly
  2. Session management relies exclusively on browser cookies. Maybe there is an abstraction layer to add for supporting both web and React Native?

For the moment, I have created a quick and dirty workaround to emulate document object (cookies are saved separately using AsyncStorage).

This is main index.js :

import buffer from 'buffer';
global.Buffer = buffer.Buffer;

import SwellDocument from 'utils/SwellDocument';
global.document = new SwellDocument();

And this is SwellUtils.tsfile for the cookie workaround:

class SwellCookie {
  public stringValue: string = '';

  public match = (re: RegExp): RegExpMatchArray | null => {
    return this.stringValue.match(re);
  }

  public toString = (): string => {
    return this.stringValue;
  }
};

export default class SwellDocument {
  private _cookie: SwellCookie = new SwellCookie();

  get cookie(): SwellCookie | string {
    return this._cookie;
  }

  set cookie(value: SwellCookie | string) {
      this._cookie.stringValue = value as string;
  }
};
@ericingram
Copy link
Contributor

@codingstyle glad you brought this up and we definitely want to support React Native. I suppose we could test whether global.document exists and if not use a mock like your example.

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

No branches or pull requests

4 participants