بدون توضیح

Nikita Chursin 87bcda1f8e added installation info to readme 3 سال پیش
.husky fa2c48498a initial commit 3 سال پیش
.vscode fa2c48498a initial commit 3 سال پیش
config fa2c48498a initial commit 3 سال پیش
force-app cf3a69182f getRecord very basic 3 سال پیش
.eslintignore fa2c48498a initial commit 3 سال پیش
.forceignore fa2c48498a initial commit 3 سال پیش
.gitignore fa2c48498a initial commit 3 سال پیش
.prettierignore fa2c48498a initial commit 3 سال پیش
.prettierrc fa2c48498a initial commit 3 سال پیش
README.md 87bcda1f8e added installation info to readme 3 سال پیش
jest.config.js fa2c48498a initial commit 3 سال پیش
package-lock.json fa2c48498a initial commit 3 سال پیش
package.json 887162c4f8 updated metadata and pushed version 0.1.0 3 سال پیش
sfdx-project.json 887162c4f8 updated metadata and pushed version 0.1.0 3 سال پیش

README.md

LWC Promise API

This is a small package that tends to replicate LWC backend APIs that don't support promises.

WHY?!

That is probably the main question you may have if you stumbled across this repo. The main reason is I don't like the @wire decorator:

  1. I hate the APIs that returns value and error as 2 output values, and you have to check that error is not empty before proceed. Just throw the goddamn error!
  2. This pervious point leads to code duplication - you have to check errors for emptiness everywhere
  3. When you need to load several records and you show a spinner while loading, your isLoading getter becomes messy.
  4. wire cuase some of our e2e tests go flaky. Probably we just don't know how to cook it here though.
  5. And the most important: getRecord cannot be promisified. At least I didn't found how to do it :(

Installation

This is distributed as an unlocked package. Just install the latest version.

Alternatively, you can clone this repo and push/deploy it to your org.

How to use it

Instead of importing getRecord from LWC library, you can just use getRecord from sfcraft_LwcApi:

import getRecord from '@salesforce/apex/sfcraft_LwcApi.getRecord';

...

async connectedCallback () {
    this.record = await getRecord({recordId: this.recordId, fields: ['Id', 'Name' ]});
}