How to use redux-orm - 10 common examples

To help you get started, we’ve selected a few redux-orm 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 SEL-Columbia / dokomoforms / dokomoforms / static / src / admin / js / create-survey / redux / models.babel.js View on Github external
console.log('mapping through choices', choice)
                return Object.assign({}, {choice_text: choice.choice_text});
            });
            if (choices.length) data = Object.assign(data, {choices: choices})
        }
        console.log('question data', data)
        delete data.id;
        delete data.node;
        return data;
    }

}

Question.fields = {
    id: attr(),
    node: oneToOne('Node'),
    allow_multiple: attr(),
    type_constraint: attr()
};

Question.modelName = 'Question';


class Node extends CRUDModel {
    denormalize() {
        console.log('this', this.ref)
        const sub_surveys = this.sub_surveys.toModelArray().map(sub_survey => sub_survey.denormalize())
        console.log('this id', this.ref.id)
        const question = this.question.denormalize();
        // console.log('the question', question)
        // const questionNode = Object.assign({}, question)
        let data = Object.assign({}, this.ref, {node: question})
github GiraffeTools / GiraffeTools / frontend / porcupine / models / link.js View on Github external
.toModelArray()
            .forEach((link) => {
              // #TODO check if this is safe when REMOVE_NODE deletes nodeModel
              if (link.portFromModel.outputParent.id == payload.parameterId) {
                link.portToModel.inputParent.update(payload.newValues);
              }
            });

        break;
    }
    return undefined;
  }
}
Link.modelName = 'Link';
Link.fields = {
  id: attr(),
  portFrom: fk({
    to: 'Port',
    as: 'portFromModel',
    relatedName: 'outputLinks',
  }),
  portTo: fk({
    to: 'Port',
    as: 'portToModel',
    relatedName: 'inputLinks',
  }),
};

export default Link;
github GiraffeTools / GiraffeTools / frontend / porcupine / selectors / selectors.js View on Github external
orm,
    (state) => state.orm,
    (session) => {
      return session.Sticky.all().toRefArray();
    }
);

export const nodes = createSelector(
    orm,
    (state) => state.orm,
    (session) => {
      return session.Node.all().toRefArray();
    }
);

export const languageNames = createSelector(
    orm,
    (state) => state.orm,
    (session) => {
      return session.Language.all()
          .toModelArray()
          .map((language) => language.name);
    }
);

export const nodesWithParameters = createSelector(
    orm,
    (state) => state.orm,
    (session) => {
      // #TODO: this graph is quite some antipattern to functional
      // programming...
      const nodes = session.Node.all().toModelArray();
github GiraffeTools / GiraffeTools / frontend / porcupine / selectors / selectors.js View on Github external
(session) => {
      return session.Node.all().toRefArray();
    }
);

export const languageNames = createSelector(
    orm,
    (state) => state.orm,
    (session) => {
      return session.Language.all()
          .toModelArray()
          .map((language) => language.name);
    }
);

export const nodesWithParameters = createSelector(
    orm,
    (state) => state.orm,
    (session) => {
      // #TODO: this graph is quite some antipattern to functional
      // programming...
      const nodes = session.Node.all().toModelArray();

      const graph = Graph.getInstance();
      let sorted;
      try {
        const order = GraphAlgorithms.topsort(graph);
        sorted = nodes.sort((a, b) => order.findIndex((id) => id === a.id)
          - order.findIndex((id) => id === b.id));
      } catch (error) {
        // #TODO not sure how to check this:
        // if (error instanceof CycleException) {
github SEL-Columbia / dokomoforms / dokomoforms / static / src / admin / js / create-survey / redux / models.babel.js View on Github external
class Bucket extends CRUDModel {
    denormalize() {
        const data = Object.assign({}, this.ref)
        delete data.id;
        delete data.survey;
        return data;
    }
};

Bucket.modelName = 'Bucket';

Bucket.fields = {
    id: attr(), // non-relational field for any value; optional but highly recommended
    bucket_type: attr(),
    bucket: attr(),
    survey: fk('Survey', 'buckets')
};


class Logic extends CRUDModel {
    denormalize() {
        const data = Object.assign({}, this.ref)
        delete data.id
        delete data.question
        return data
    }
};

Logic.modelName = 'Logic';

Logic.fields = {
    id: attr(),
github GiraffeTools / GiraffeTools / frontend / porcupine / models / link.js View on Github external
.forEach((link) => {
              // #TODO check if this is safe when REMOVE_NODE deletes nodeModel
              if (link.portFromModel.outputParent.id == payload.parameterId) {
                link.portToModel.inputParent.update(payload.newValues);
              }
            });

        break;
    }
    return undefined;
  }
}
Link.modelName = 'Link';
Link.fields = {
  id: attr(),
  portFrom: fk({
    to: 'Port',
    as: 'portFromModel',
    relatedName: 'outputLinks',
  }),
  portTo: fk({
    to: 'Port',
    as: 'portToModel',
    relatedName: 'inputLinks',
  }),
};

export default Link;
github GiraffeTools / GiraffeTools / frontend / porcupine / models / language.js View on Github external
name: nodeLanguage,
                nodes: [payload.id],
              });
            }
          });
        break;
    }
    return undefined;
  }
}
Language.modelName = 'Language';
Language.fields = {
  name: attr(),
  numberInEditor: attr(),
  // languages
  nodes: many({
    to: 'Node',
    as: 'nodes',
    relatedName: 'languages',
  }),
};

export default Language;
github N3TC4T / Nearby-Live / src / redux / core / stream / models.js View on Github external
}

    static get modelName() {
        return 'Comment';
    }

    static get options() {
        return {
            idAttribute: 'id'
        };
    }
}

/* Schema ==================================================================== */

const schema = new ORM();
schema.register(Post, Comment);

/* Export Schema ==================================================================== */

export default schema;
github N3TC4T / Nearby-Live / src / redux / core / system-notifications / models.js View on Github external
}

    static get modelName() {
        return 'Notification';
    }

    static get options() {
        return {
            idAttribute: 'id'
        };
    }
}

/* Schema ==================================================================== */

const schema = new ORM();
schema.register(Notification);

/* Export Schema ==================================================================== */

export default schema;
github N3TC4T / Nearby-Live / src / redux / core / conversations / models.js View on Github external
}

    static get modelName() {
        return 'Conversation';
    }

    static get options() {
        return {
            idAttribute: 'id'
        };
    }
}

/* Schema ==================================================================== */

const schema = new ORM();
schema.register(Message, Conversation);

/* Export Schema ==================================================================== */

export default schema;

redux-orm

Simple ORM to manage and query your state trees

MIT
Latest version published 4 years ago

Package Health Score

51 / 100
Full package analysis