How to use the cosmicjs.getObjects function in cosmicjs

To help you get started, we’ve selected a few cosmicjs 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 cosmicjs / cosmicapp-voting-app / components / AppState.js View on Github external
showResults() {
    getObjects({ bucket: config.cosmicjs.bucket }, (err, res) => {
      this.is_saving = false
      this.poll.vote_counted = true
      if (res.objects) {
        const votes = res.objects.type.votes
        this.votes = votes
        this.show_results = true
        // Redo totals
        let polls = res.objects.type.polls
        polls = this.getVoteTotals(polls, votes)
        const poll_index = _.findIndex(this.polls, { _id: this.poll._id })
        polls[poll_index].vote_counted = true
        this.polls = polls
      }
    })
  }
  getVoteTotals(polls, votes) {
github tonyspiro / react-chat-app / app-client.js View on Github external
componentDidMount() {
    let data = this.state.data
    setTimeout(() => {
      this.refs.author.refs.input.focus()
    }, 100)
    const socket = io()
    Cosmic.getObjects(config, (err, res) => {
      const messages = res.objects.type.messages
      if (messages) {
        messages.reverse()
        this.setState({
          data: {
            author: data.author,
            messages
          }
        })
      }
    })
    // Listen for messages coming in
    socket.on('chat message', message => {
      data = this.state.data
      const messages = this.state.data.messages
      if (data.author !== message.metafield.author.value) {
github cosmicjs / cosmicapp-voting-app / components / AppState.js View on Github external
constructor() {
    // Get all polls and votes
    getObjects({ bucket: config.cosmicjs.bucket }, (err, res) => {
      if (res.objects) {
        let polls = res.objects.type.polls
        const votes = res.objects.type.votes
        polls = this.getVoteTotals(polls, votes)
        // If already voted
        polls.forEach((poll, i) => {
          if (window.localStorage.getItem(polls[i]._id)) {
            this.options_selected.push({ poll: polls[i]._id, value: window.localStorage.getItem(polls[i]._id) })
            polls[i].vote_counted = true
          }
        })
        this.polls = polls
        this.votes = votes
        const slug = window.location.pathname.replace('/', '')
        if (slug) {
          const poll = _.find(res.objects.type.polls, { slug })
github tonyspiro / react-universal-blog / actions / actions.js View on Github external
export function getStore(callback){
  
  let pages = {}

  Cosmic.getObjects(config, function(err, response){
    
    let objects = response.objects
    
    /* Globals
    ======================== */
    let globals = AppStore.data.globals
    globals.text = response.object['text']
    let metafields = globals.text.metafields
    let menu_title = _.find(metafields, { key: 'menu-title' })
    globals.text.menu_title = menu_title.value

    let footer_text = _.find(metafields, { key: 'footer-text' })
    globals.text.footer_text = footer_text.value

    let site_title = _.find(metafields, { key: 'site-title' })
    globals.text.site_title = site_title.value
github tonyspiro / tonyspiro.com-react / stores / AppStore.js View on Github external
init: function(payload) {
    
    let _this = this;
    let pages = {};

    _this.data.ready = false;
    _this.data.pages = [];

    Cosmic.getObjects(config, function(err, response){
      
      let objects = response.objects;
      
      /* Globals
      ======================== */
      let globals = _this.data.globals;
      globals.text = response.object['text'];
      let metafields = globals.text.metafields;
      let menu_title = _.findWhere(metafields, { key: 'menu-title' });
      globals.text.menu_title = menu_title.value;

      let footer_text = _.findWhere(metafields, { key: 'footer-text' });
      globals.text.footer_text = footer_text.value;

      let site_title = _.findWhere(metafields, { key: 'site-title' });
      globals.text.site_title = site_title.value;
github tonyspiro / react-flux-cosmicjs / stores / ListStore.js View on Github external
init: function(items){

    let _this = this;

    Cosmic.getObjects(config, function(err, response){

      let items = response.objects.type['list-items'];
      items = _.sortBy(items, 'order');
      _this.items = items;
      _this.emitChange();

    });
  },

cosmicjs

The official client module for Cosmic. This module helps you easily add dynamic content to your website or application using the Cosmic headless CMS.

MIT
Latest version published 2 years ago

Package Health Score

42 / 100
Full package analysis