Giter Club home page Giter Club logo

falcor-local-datasource's People

Contributors

jameslaneconkling avatar

Stargazers

 avatar  avatar

Watchers

 avatar

falcor-local-datasource's Issues

add debug mode

to log the returned JSONGraphEnvelope from get/set/call. This could help understand the relationship between:

  • a request's pathSets
  • the dataSource's JSONGraphEnvelope response
  • the model's JSONEnvelope response

bug on readme page

Sometimes I wonder if anyone tests out their posted code. In your example, under the todos key, you use ids 'id_0' and 'id_1', while under the key todosById you use ids 'id_1' and 'id_2'.

Missing check in function isPathValues

Version 1.2.0 (the latest, as far as I know) - in utils.js function isPathValues() fails to check if it has been passed an array. So, if you pass it a JSONGraphEnvelope, which is an object, an exception is thrown when the function calls .reduce() on it. A simple "Array.isArray(pathValues) &&" preceding that fixes the problem.

Issue with sample code

The sample code seems to work fine, but the problem is that if you ask for the number of todos before AND between the 2 calls, you'll get 2. However, if you ask for the number of todos AFTER the 2 calls, you'll get 4! Here is my code. Note that I used the code in the README file to set up the model, but used (my preferred) async/await to query the model. I did need to make these changes:

  1. Create and call a function main() so I could mark it as an async function, and therefore use await.
  2. Use require('falcor-local-datasource') to retrieve the LocalDatasource object
  3. Fixed an issue with the id's used, which I previously reported and thought was fixed, but it looks like it's still there (i.e. using 'id_0' and 'id_1' in one place, but 'id_1' and 'id_2' in another place)
const falcor = require('falcor');
// const LocalDatasource = require('../src/index');
const LocalDatasource = require('falcor-local-datasource');

async function main() {

const graph = {
  todos: {
    0: { $type: 'ref', value: ['todosById', 'id_0'] },
    1: { $type: 'ref', value: ['todosById', 'id_1'] },
    length: 2,
    add(graph, args) {
      const newTodoLabel = args[0];
      const todoCount = graph.todos.length;
      // NOTE: this is a pretty naive way to derive new ids.  a more robust approach might generate unique ids using
      // a specific node in the graph, or use a closure, or some other mechanism to yield unique incremental values
      const newId = `id_${todoCount}`;

      // return array of pathValues
      return [
        {
          path: ['todos', todoCount],
          value: { $type: 'ref', value: ['todosById', newId] }
        },
        {
          path: ['todosById', newId, 'label'],
          value: newTodoLabel
        },
        {
          path: ['todosById', newId, 'completed'],
          value: false
        },
        {
          path: ['todos', 'length'],
          value: todoCount + 1
        }
      ];
    }
  },
  todosById: {
    id_0: { label: 'tap dance', completed: false },
    id_1: { label: 'see above', completed: false }
  }
};

const model = new falcor.Model({ source: new LocalDatasource(graph) });


try {
	let n = await model.getValue('todos.length');
	console.log(`1. There are ${n} todos`);

	await model.call(['todos', 'add'], ['dupstep dance party']);

	n = await model.getValue('todos.length');
	console.log(`2. There are ${n} todos`);

	await model.call(['todos', 'add'], ['jumpstyle'],
	                 [[['label', 'completed']]],
	                 [['length']]);

	n = await model.getValue('todos.length');
	console.log(`3. There are ${n} todos`);
	}
catch (err) {
	console.error(err);
	}
} // main()

main();

Now, there is a way to fix this code, i.e. get 2, then 3, then 4 for the number of todos, but I don't think I should need to do this. The fix is to change the first "call" to:

await model.call(['todos', 'add'], ['dupstep dance party'], [], [['length']]);
The way I understand the 4th argument is that it specifies values that I need in the code that uses model.call(), i.e. the code above, and I don't need it since I'm going to make another model.call() immediately after. However, the JavaScript function that implements the "add" operation returns 4 paths that should force the local cache to update its value for todos.length, and it doesn't seem to be doing that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.