How to use the mobx.decorate function in mobx

To help you get started, we’ve selected a few mobx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jamieYou / weapp-starter-kit / src / store / weapp / helper.js View on Github external
function autoObservables(target) {
  const obj = {}
  Object.keys(target).forEach(key => {
    const descriptor = Object.getOwnPropertyDescriptor(target, key)
    if (!/^(\$|_)/.test(key) && typeof descriptor.value !== 'function' && !isObservable(descriptor.value)) {
      obj[key] = observable
    }
  })
  decorate(target, obj)
}
github async-labs / saas / app / lib / store / index.ts View on Github external
};

  private loadCurrentTeamData() {
    if (this.currentTeam) {
      this.currentTeam
        .loadInitialMembers()
        .catch((err) => console.error('Error while loading Users', err));

      this.currentTeam
        .loadDiscussions()
        .catch((err) => console.error('Error while loading Discussions', err));
    }
  }
}

decorate(Store, {
  teams: observable,
  isLoadingTeams: observable,
  isInitialTeamsLoaded: observable,
  currentUser: observable,
  currentTeam: observable,
  currentUrl: observable,
  isLoggingIn: observable,

  changeCurrentUrl: action,
  addTeam: action,
  loadTeams: action,
  setCurrentTeam: action,
});

let store: Store = null;
github datadotworld / chart-builder / src / components / LicenseModal.js View on Github external
<div data-test="license-text">
              {this.licenseText}
            </div>
          ) : (
            
          )}
        
        
          <button>Close</button>
        
      
    )
  }
}

decorate(LicenseModal, {
  licenseText: observable
})

export default observer(LicenseModal)
github zenprotocol / explorer / src / pages / oracle / components / Filters / Filters.jsx View on Github external
<div>
                <button type="dark-2" size="sm">
                  Reset all
                </button>
              </div>
            
          
        
      
    );
  }
}

decorate(Filters, {
  allTickers: computed,
});

Filters.propTypes = {
  filterState: PropTypes.shape({
    date: PropTypes.string.isRequired,
    tickers: PropTypes.array.isRequired,
  }),
  allTickers: PropTypes.array.isRequired,
  defaultDate: PropTypes.string,
};

Filters.defaultProps = {
  defaultDate: TextUtils.getISODateFromNow(),
};
github zenprotocol / explorer / src / pages / contractTemplates / CreateContractTemplate.jsx View on Github external
}

  getValidationDisplayProp(key) {
    return {
      style: {
        display: this.data[key].valid ? 'none' : 'block',
      },
    };
  }
}
CreateContractTemplate.propTypes = {
  template: PropTypes.object.isRequired,
  tickerPrices: PropTypes.object.isRequired,
};

decorate(CreateContractTemplate, {
  data: observable,
  valid: observable,
  handleNameChange: action,
  handleDateChange: action,
  resetForm: action,
  validate: action,
  tickers: computed,
  dataFlattened: computed,
});

export default observer(CreateContractTemplate);
github apsavin / pgrights / src / models / DbPoliciesManager.js View on Github external
const policiesByRole = {};
    this.policies.forEach(policy =&gt; {
      policy.roles.forEach(role =&gt; {
        policiesByRole[role] = policiesByRole[role] || [];
        policiesByRole[role].push(policy);
      });
    });
    return policiesByRole;
  }

  getPolicies(role): Array {
    return this.policiesByRole[role] || NO_POLICIES;
  }
}

decorate(DbPoliciesManager, {
  policies: observable,
  policiesByRole: computed,
});

export default DbPoliciesManager;
github xt / nitro2 / packages / header / app / store / store.js View on Github external
import { decorate, observable, computed } from "mobx";

class headerStore {
    constructor() {
        this.likedItems = [];
    }

    get getLikedItemsCount() {
        return this.likedItems.length;
    }
}

decorate(headerStore, {
    likedItems: observable,
    getLikedItemsCount: computed
})

export default new headerStore();
github apsavin / pgrights / src / models / DbConnection.js View on Github external
this.roles[name] = { oid, name, isSuperUser: rolsuper, bypassRLS: rolbypassrls };
      rolesByIds[oid] = this.roles[name];
    });
    this.rolesNames = Object.keys(this.roles);
    roles.forEach((role) => {
      const { rolname: name, parents_oids: parentsOids } = role;
      this.roles[name].parents = parentsOids.filter(Boolean).map(oid => rolesByIds[oid].name);
    });
  });

  get isFetched() {
    return this.rolesFetcher.inSuccessState && this.schemasFetcher.inSuccessState;
  }
}

decorate(DbConnection, {
  roles: observable,
  rolesNames: observable,
  schemas: observable,
  schemasNames: observable,
  isFetched: computed,
});

export default DbConnection;
github xt / nitro2 / packages / products / app / store / store.js View on Github external
import { decorate, observable, computed } from "mobx";

class productsStore {
  constructor() {
    this.likedItems = [];
    this.currentLikedItem = {};
  }
  get getLikedItems() {
    return this.likedItems;
  }
}

decorate(productsStore, {
  likedItems: observable,
  getLikedItems: computed
});

export default new productsStore();