From 1b0a80521bb1653b024ed8577f9a8d48f09339fe Mon Sep 17 00:00:00 2001 From: Dawson Botsford Date: Fri, 14 Feb 2020 16:37:09 -0500 Subject: [PATCH] Update encode/decode to save 100's of KB's of JS! We experienced some nasty bundle sizes in production over at https://everipedia.org and found this simple change to reduce the bundle size over 500KB! --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b0c6b6d60..2d6716f1d 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,12 @@ const { Api, JsonRpc, RpcError } = require('eosjs'); const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); // development only const fetch = require('node-fetch'); // node only; not needed in browsers const { TextEncoder, TextDecoder } = require('util'); // node only; native TextEncoder/Decoder -const { TextEncoder, TextDecoder } = require('text-encoding'); // React Native, IE11, and Edge Browsers only +const textEncoder = new TextEncoder(); +const textDecoder = new TextDecoder(); + +const { TextEncoder, TextDecoder } = require('text-encoding-shim'); // React Native, IE11, and Edge Browsers only +const textEncoder = new TextEncoder('utf-8'); +const textDecoder = new TextDecoder('utf-8'); ``` ## Basic Usage @@ -63,7 +68,7 @@ const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch }); Include textDecoder and textEncoder when using in Node, React Native, IE11 or Edge Browsers. ```js -const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }); +const api = new Api({ rpc, signatureProvider, textDecoder, textEncoder}); ``` ### Sending a transaction