All Projects → ruslan-kurchenko → Sfdc Lax

ruslan-kurchenko / Sfdc Lax

Licence: mit
The service Lightning Component to write a clear asynchronous JavaScript code

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Sfdc Lax

sfdx-lightning-api-component
⚡️ Promise-based service component for calling REST API from Lightning Aura Components without Named Credentials.
Stars: ✭ 62 (-43.12%)
Mutual labels:  promise, salesforce, aura
Sfdc Ui Lookup
Salesforce Lookup Component (Aura version, maintenance only, see LWC version for updates)
Stars: ✭ 94 (-13.76%)
Mutual labels:  salesforce, aura
eslint-plugin-aura
Salesforce Lightning (Aura) specific linting rules for ESLint
Stars: ✭ 24 (-77.98%)
Mutual labels:  salesforce, aura
one-pub-sub-lwc
One PubSub: A Declarative PubSub Library for Lightning Web Component and Aura Component
Stars: ✭ 19 (-82.57%)
Mutual labels:  salesforce, aura
Vim Force.com
Vim plugin for force.com
Stars: ✭ 98 (-10.09%)
Mutual labels:  salesforce
Promise Poller
A basic poller built on top of promises
Stars: ✭ 88 (-19.27%)
Mutual labels:  promise
Datakernel
Alternative Java platform, built from the ground up - with its own async I/O core and DI. Ultra high-performance, simple and minimalistic - redefines server-side programming, web-development and highload!
Stars: ✭ 87 (-20.18%)
Mutual labels:  promise
Easy Spaces Lwc
Sample application for Lightning Web Components on Salesforce Platform. Part of the sample gallery. Event management use case. Get inspired and learn best practices.
Stars: ✭ 104 (-4.59%)
Mutual labels:  salesforce
Vue Promised
💝 Composable Promises & Promises as components
Stars: ✭ 1,325 (+1115.6%)
Mutual labels:  promise
Angular2 Promise Buttons
Chilled loading buttons for angular2
Stars: ✭ 84 (-22.94%)
Mutual labels:  promise
Aura.autoload
A PSR-0 compliant autoloader
Stars: ✭ 93 (-14.68%)
Mutual labels:  aura
Awesome Low Code
Awesome Low-Code Application Platforms | 全球低代码平台开发资源大全
Stars: ✭ 90 (-17.43%)
Mutual labels:  salesforce
Es6 Promise Polyfill
ES6 Promise polyfill
Stars: ✭ 99 (-9.17%)
Mutual labels:  promise
Policy sentry
IAM Least Privilege Policy Generator
Stars: ✭ 1,284 (+1077.98%)
Mutual labels:  salesforce
Force Dev Tool
[DEPRECATED] Command line tool supporting the Force.com development lifecycle
Stars: ✭ 106 (-2.75%)
Mutual labels:  salesforce
Promises Book
JavaScript Promiseの本
Stars: ✭ 1,264 (+1059.63%)
Mutual labels:  promise
Dynamodb Oop
Speak fluent DynamoDB, write code with fashion, I Promise() 😃
Stars: ✭ 104 (-4.59%)
Mutual labels:  promise
Lightningexamples
Examples of Salesforce Lightning Components
Stars: ✭ 90 (-17.43%)
Mutual labels:  salesforce
Taskorama
⚙ A Task/Future data type for JavaScript
Stars: ✭ 90 (-17.43%)
Mutual labels:  promise
Testdatafactory
The ultimate Apex Test Data Factory 🏭
Stars: ✭ 108 (-0.92%)
Mutual labels:  salesforce

Logo

Lax is a Lightning Component to write a clear asynchronous JavaScript code. It helps you to remove the boilerplate code in Lightning Components. Lax combines capabilities to efficiently call Apex with powerful exception handling and list of utility techniques, giving you an ability to write asynchronous code in a modern approach.

Features

  • lax gets the context of consumer component
  • Supports the Promise API
    • Set server-side action callback (success, failure, incomplete)
    • Chain server-side actions
    • Perform multiple concurrent server-side actions
    • Call Lightning Data Service actions (create/save/delete)
    • Dynamically create components
  • Construct and enqueue server-side action using Builder Pattern approach
  • Construct and fire Application or Component event using Builder Pattern approach
  • Automatically wraps callback by $A.getCallback()
  • Use lax in consumer's component aura:valueInit event handler

Installing

Click on the button below to deploy the component to the org

Deploy

Usage

Define lax component in a custom component markup:

<!-- ContactsComponent.cmp -->
<aura:component controller="LaxExamplesController">
    <!-- Define lax component and pass consumer's component object as a context attribute (required) -->
    <c:lax context="{!this}" />
    
    <aura:attribute name="records" type="Contact[]" access="private"/>
    <aura:handler name="init" action="{!c.onInit}" value="{!this}" />
</aura:component>

Enqueue an action in component's aura:valueInit event handler function to get initial data:

// ContactsComponentController.js
({
    onInit: function (component, event, helper) {
        // equeue getContacts server-side action and set the callback
        component.lax.enqueue('c.getContacts').then(contacts => {
            // $A.getCallback is not required. lax does it automatically
            component.set('v.records', contacts);
        });
    }
});
NOTE

API Reference

Navigate to component API Reference documentation to see full list of available functions and capabilities

Examples

Actions can be enqueued by passing the relevant parameters and options.

lax.enqueue(name[, params[, options]]).then(callback) - call action with parameters, options and simple callback
component.lax.enqueue('c.getContact', { id: recordId }, { background: true })
    .then(contact => {
        component.set('v.record', contact);
    });
NOTE
lax.enqueue(name[, params[, options]]).then(callback).catch(callback) - handle errors thrown by the server
component.lax.enqueue('c.save', { record: record })
    .then(id => {
        component.set('v.record.id', id);
    })
    .catch(errors => {
        console.error(errors);
    });
lax.enqueue(name[, params[, options]]).then(callback).then(callback) - performing multiple chained actions
component.lax.enqueue('c.getParentValue')
    .then(parentValue => {
        component.set('v.parentValue', parentValue);
        return component.lax.enqueue('c.getDependentValue', { parentValue: parentValue });
    })
    .then(dependentValue => {
        component.set('v.dependentValue', dependentValue);
    });
lax.enqueueAll(actions).then(callback) - performing multiple concurrent actions
component.lax.enqueueAll([
    // { name : '...', params: {...}, options: {...} }
    { name: 'c.getContacts' }, 
    { name: 'c.getAccounts' },
    { name: 'c.getOpportunities' }
])
.then(results => {
    // results: [ [contacts], [accounts], [opportunities] ]
    const contacts = results[0];
    const accounts = results[1];
    const opportunities = results[2];
});
NOTE
  • actions - The array of actions to enqueue concurrently:
    • name - the name of an action
    • params - an object with list of parameters (optional)
    • options - an object with list of options that can be applied to the action (optional)
  • The success callback will call when all enqueued actions be back from the server
  • results - The list of values returned from enqueued actions
lax.action(name) - create and return LaxAction builder
component.lax
    .action('c.getContact')
    .setStorable()
    .setParams({ id: recordId })
    .setThen(contact => {
        component.set('v.record', contact)
    })
    .setCatch(error => {
        console.error(error);
    })
    .enqueue();
NOTE
  • LaxAction is an object with the list of functions to construct a server-side action
  • The approach is useful for Storable actions, because LaxAction does not use Promise API
  • Actions can't be chained or called concurrently using LaxAction builder approach
  • The list of function available on LaxAction:
    • setParams(params) - set an object with list of parameters
    • setThen(callback) - set success callback function
    • setCatch(callback) - set failure callback function to handler server-side errors
    • enqueue() - enqueue constructed action. The only function LaxAction that return undefined
    • setStorable() - set an action as a Storable
    • setBackground() - set an action as a Background
lax.lds(id) - create and return LaxDataService to execute Lightning Data Service (LDS) actions based on Promise API
component.lax.lds('serviceAuraId');
lax.lds(id).getNewRecord(sobjectType[, recordTypeId[, skipCache]]) - the function to load a record template to the LDS targetRecord attribute
component.lax.lds('contactRecordCreator')
  .getNewRecord('Contact')
  .then(() => {
    const rec = component.get("v.newContact");
    const error = component.get("v.newContactError");

    if (error || (rec === null)) {
      console.log("Error initializing record template: " + error);
    }
  });
lax.lds(id).saveRecord() - the function to save the record that loaded to LDS in the edit EDIT mode
component.lax.lds('recordHandler')
  .saveRecord()
  .then(result => {
    // handle "SUCCESS" or "DRAFT" state
  })
  .error(e => {
    // handle "ERROR" state
  })
  .incomplete(e => {
    // handle "INCOMPLETE" state
  })
lax.lds(id).deleteRecord() - the function to delete a record using LDS
component.lax.lds('recordHandler')
  .deleteRecord()
  .then(result => {
    // handle "SUCCESS" or "DRAFT" state
  })
  .catch(e => {
    // handle "ERROR" or "INCOMPLETE" state. 
    // or you can use divided handlers: .error(), .incomplete()
  })
lax.event(eventName) - creates an object with LaxEventBuilder prototype and the context event by provided name
// Fire Component Event:
component.lax.event('sampleComponentEvent')
  .setParams({payload: { type: 'COMPONENT'} })
  .fire();

// Fire Application Event:
component.lax.event('e.c:AppEvent')
  .setParams({payload: { type: 'APPLICATION'} })
  .fire();
lax.createComponent(type[, attributes]) - creates a component from a type and a set of attributes
component.lax.createComponent('aura:text', { value: 'Single Component Creation' })
  .then(result => {
    // result has a property "component" with created component
    single.set('v.body', result.component);
  })
  .catch(e => {
    // handle "ERROR" or "INCOMPLETE" state
  });
lax.createComponent(type[, attributes]) - creates an array of components from a list of types and attributes
lax.createComponents([
    ['aura:text', { value: 'Multiple Component Creation #1'}],
    ['aura:text', { value: 'Multiple Component Creation #2'}],
    ['aura:text', { value: 'Multiple Component Creation #3'}]
  ])
  .then(result => {
    // result has a property "components" with list of created components
    multiple.set('v.body', result.components);
  })
  .incomplete(e => {
    // handle "INCOMPLETE" state
  })
  .error(e => {
    // handle "ERROR" state
  });

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].