Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (query) {
const qArgs = [query, datascript.db(this.conn)];
if (params) {
qArgs.push(params);
}
if (rules) {
qArgs.push(rules);
}
let queryResult = datascript.q(...qArgs);
this.setState({ result: queryResult || this.state.result });
return;
}
if (pull) {
const { entityIds } = this.props;
let queryResult = datascript.pull_many(datascript.db(this.conn), pull, entityIds);
this.setState({ result: queryResult || this.state.result });
return;
}
if (dbConn) {
let queryResult = dbConn(this.conn);
this.setState({ result: queryResult || this.state.result });
}
}
const { result, params, parsedQueryAttrs } = this.state;
if (report) {
const someQueryAttrChanged = report.tx_data
.map(({a}) => a)
.some(a => parsedQueryAttrs[a]);
//Did this last transaction not contain changes to any fields referenced
//by this query? Skip the re-query (and corresponding component update)
if (query && !someQueryAttrChanged) {
return;
}
}
if (query) {
const qArgs = [query, datascript.db(this.conn)];
if (params) {
qArgs.push(params);
}
if (rules) {
qArgs.push(rules);
}
let queryResult = datascript.q(...qArgs);
this.setState({ result: queryResult || this.state.result });
return;
}
if (pull) {
const { entityIds } = this.props;
let queryResult = datascript.pull_many(datascript.db(this.conn), pull, entityIds);
this.setState({ result: queryResult || this.state.result });
return;
dbConn: (conn) => (
datascript.datoms(datascript.db(conn), ':aevt', 'name')
)
});
transactData = (data, txMsg) => {
datascript.transact(this.conn, data, txMsg);
}
{
':db/id': -2,
name: 'David',
follows: [-3, -1]
},
{
':db/id': -3,
name: 'Jane'
}
];
/**
* Transact in the data, to be stored and indexed by datascript for performant
* querying.
*/
datascript.transact(conn, datoms);
return conn;
};
*/
const twitterUserSchema = {
name: {
':db/cardinality': ':db.cardinality/one',
':db/unique': ':db.unique/identity'
},
follows: {
':db/cardinality': ':db.cardinality/many',
':db/valueType': ':db.type/ref'
}
};
/**
* Create connection to db (that's been instantiated with the schema above.)
*/
const conn = datascript.create_conn(twitterUserSchema);
/**
* Define some seed data; including some `follower` references (that make
* use of a temporary id to point to other entities within the array.)
*/
const datoms = [
{
':db/id': -1,
name: 'John',
follows: -3
},
{
':db/id': -2,
name: 'David',
follows: [-3, -1]
},
componentWillMount() {
this.execQuery();
datascript.listen(this.conn, this.execQuery);
}
//Did this last transaction not contain changes to any fields referenced
//by this query? Skip the re-query (and corresponding component update)
if (query && !someQueryAttrChanged) {
return;
}
}
if (query) {
const qArgs = [query, datascript.db(this.conn)];
if (params) {
qArgs.push(params);
}
if (rules) {
qArgs.push(rules);
}
let queryResult = datascript.q(...qArgs);
this.setState({ result: queryResult || this.state.result });
return;
}
if (pull) {
const { entityIds } = this.props;
let queryResult = datascript.pull_many(datascript.db(this.conn), pull, entityIds);
this.setState({ result: queryResult || this.state.result });
return;
}
if (dbConn) {
let queryResult = dbConn(this.conn);
this.setState({ result: queryResult || this.state.result });
}
}
componentWillUnmount() {
datascript.unlisten(this.conn);
}