Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

Refactor with Sync 1.0 changes #60

Merged
merged 1 commit into from
May 14, 2015

Conversation

superkhau
Copy link
Contributor

Connect to strongloop-internal/scrum-loopback#214

@superkhau superkhau self-assigned this Apr 6, 2015
@superkhau superkhau changed the title Enable change tracking Refactor with Sync 1.0 changes Apr 16, 2015
@bajtos
Copy link
Member

bajtos commented Apr 21, 2015

Can you please make the commit message of 7a545e7 more explanatory? Change tracking was already enabled.

@superkhau superkhau force-pushed the feature/refactor-with-sync-1.0-changes branch 2 times, most recently from 7a0a761 to 87f43a9 Compare April 21, 2015 21:40
@superkhau
Copy link
Contributor Author

@bajtos Running grunt alone shows this error:

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.31 server started at http://localhost:8080/
INFO [launcher]: Starting browser PhantomJS
WARN [watcher]: Pattern ".../loopback-example-offline-sync/client/ngapp/test/mock/**/*.js" does not match any file.
INFO [PhantomJS 1.9.8 (Mac OS X)]: Connected on socket z-UTHdFtwZ2ZLg01gBEa with id 33976604
PhantomJS 1.9.8 (Mac OS X) ERROR
  TypeError: 'undefined' is not a function (evaluating 'Number.isFinite(parseInt(v, 10))')
  at .../loopback-example-offline-sync/client/lbclient/browser.bundle.js:16224


Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

Do you know what this means?

@superkhau superkhau force-pushed the feature/refactor-with-sync-1.0-changes branch 3 times, most recently from 4e7f5ec to e1e9fb4 Compare April 22, 2015 05:24
@superkhau
Copy link
Contributor Author

Also getting:

Running "mochaTest:server" (mochaTest) task

  Todo
    New todo empty data
      POST /api/Todos
        ✓ should be allowed
        ✓ should have statusCode 200
        1) should respond with a new todo # this is failing
  ...
  1 failing

  1) Todo New todo empty data POST /api/Todos should respond with a new todo:
     AssertionError: null == true
      at Context.<anonymous> (server/test/todo.test.js:23:9)

For some reason, the test is returning an actual mongo id (might be something to do with the "before save" operation hook).

@superkhau superkhau force-pushed the feature/refactor-with-sync-1.0-changes branch 3 times, most recently from 9e71a07 to 00e1980 Compare April 22, 2015 05:30
@@ -19,7 +19,8 @@ describe('Todo', function() {
assert.equal(this.res.statusCode, 200);
});

it('should respond with a new todo', function() {
it.skip('should respond with a new todo', function() {
console.log(this.res.body.id);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.res.body.id returns an actual MongoDB id instead of the t-math id. Any idea why this is happening?

@superkhau superkhau force-pushed the feature/refactor-with-sync-1.0-changes branch 2 times, most recently from 922dac1 to de3fc30 Compare April 22, 2015 05:45
@bajtos
Copy link
Member

bajtos commented Apr 22, 2015

Number.isFinite

See strongloop/loopback-boot#124

Todo New todo empty data POST /api/Todos should respond with a new todo

No idea.

this.res.body.id returns an actual MongoDB id instead of the t-math id. Any idea why this is happening?

I think that's because all Todo ids are initialized with a GUID value - see "defaultFn": "guid" in model config. This is intended and required for sync to work correctly.

@superkhau superkhau force-pushed the feature/refactor-with-sync-1.0-changes branch from de3fc30 to 15f3a1a Compare April 22, 2015 06:51
RemoteTodo,
since.push,
function pushed(err, conflicts, cps) {
console.log('LR', arguments);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting [Error: Invalid URI "/api/Todos/checkpoint", undefined, undefined] here also.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the URL "/api/Todos/checkpoint" available in the explorer?

Please create a new RemoteTodo model per the instructions in docs and use it instead of the base Todo model here.

- var RemoteTodo = client.models.Todo;
+ var RemoteTodo = client.models.RemoteTodo;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem is caused by the fact that your RemoteTodo (=base Todo ATM) has change tracking enabled, thus it's trying to rectify changes via REST API. That's why you need to create a new subclass RemoteTodo which will not track changes but still provide the replication API. See the docs for more details.

For each replicated model, create two new client-only subclasses:

  • A local model that will use local storage to persist the changes offline
  • A remote model that will be connected to the server and used as a target for replication. This model will have change tracking disabled (because the server is already handling it) and enable only the replication REST API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@superkhau superkhau force-pushed the feature/refactor-with-sync-1.0-changes branch from 15f3a1a to e808aed Compare April 22, 2015 20:35
RemoteTodo,
since.push,
function pushed(err, conflicts, cps) {
if (err) throw err;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still getting Invalid URI "/api/Todos/checkpoint" here. Do you see any obvious changes I may have missed? FYI, I just copied/pasted all the code from the confluence docs this time.

@superkhau
Copy link
Contributor Author

See strongloop/loopback-boot#124

I see, will bump loopback-boot version when that gets merged.

No idea.

Going to skip the test then.

I think that's because all Todo ids are initialized with a GUID value - see "defaultFn": "guid" in model config. This is intended and required for sync to work correctly.

I see. So it's possible this initialization is causing that one test to fail then. Anyways, I'm skipping the test, so its not blocking what we're trying to do anyways.

@@ -2,6 +2,6 @@ var GLOBAL_CONFIG = require('../../global-config');

module.exports = {
remote: {
url: GLOBAL_CONFIG.restApiUrl
url: 'http://localhost:3000' + GLOBAL_CONFIG.restApiUrl
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured out the problem. This might be a bug, but you need to add the fully qualified URL and domain for things to work properly. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See strongloop/strong-remoting#200

The host + port must not be hard-coded here. Check the way how GLOBAL_CONFIG is constructed and modify the code to produce a full URL, so that datasources.local.js can stay unchanged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that host + port value must be synchronized with settings in server/config.json. When you change port in server/config.json, the client app should automatically pick it up after rebuild via grunt.

@bajtos
Copy link
Member

bajtos commented Apr 23, 2015

Going to skip the test then.

No no, don't skip the test, fix it instead. As you can see, it's checking the format of the id property:

assert(this.res.body.id.match(/t-\d+/));

Since you are no longer generating ids as t-XYZA, you should rework the test to check something else that makes sense. For example that id has a GUID format.

Or simply remove it('should respond with a new todo') completely, since the other tests are already testing that a new Todo instance can be created.

@superkhau superkhau force-pushed the feature/refactor-with-sync-1.0-changes branch from 57eeea2 to f540e99 Compare April 23, 2015 20:12
@superkhau
Copy link
Contributor Author

No no, don't skip the test...

Updated the test to check for proper GUID format.

@superkhau superkhau force-pushed the feature/refactor-with-sync-1.0-changes branch from f540e99 to b4ee01c Compare April 24, 2015 04:13
@superkhau superkhau force-pushed the feature/refactor-with-sync-1.0-changes branch from 64c1617 to 5729f88 Compare April 24, 2015 05:50
@superkhau superkhau mentioned this pull request Apr 24, 2015
@superkhau
Copy link
Contributor Author

@bajtos Please code review. If you see anything obvious that needs fixing, please add it to this PR yourself as I will be away for 2 weeks. If there is no hurry to merge this, then I can finish it up when I'm back. As for the easy-to-read GUID feature, I created a separate issue at #62 and will work on it after I'm back.

@@ -1,6 +1,7 @@
{
"remote": {
"connector": "remote"
"connector": "remote",
"url": "/api"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, this value is overriden by datasources.local.js and thus not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed url k/v.

@bajtos bajtos added this to the #Epic: Offline Sync V1 milestone Apr 24, 2015
@chandadharap
Copy link

Assigning back to @bajtos , Simon on PTO

@chandadharap chandadharap assigned bajtos and unassigned superkhau Apr 27, 2015
@bajtos bajtos assigned superkhau and unassigned bajtos May 5, 2015
@bajtos
Copy link
Member

bajtos commented May 5, 2015

Reassigning back to Simon, offline sync is not urgent now.

@ritch
Copy link
Member

ritch commented May 12, 2015

@superkhau @bajtos is this good to go?

@superkhau
Copy link
Contributor Author

@ritch Almost. I need to refactor the configs based on @bajtos's comments and then it should be good to go.

@superkhau superkhau force-pushed the feature/refactor-with-sync-1.0-changes branch from 5729f88 to d1345fa Compare May 13, 2015 07:15
@superkhau
Copy link
Contributor Author

@bajtos Code review again please.

@superkhau superkhau assigned bajtos and unassigned superkhau May 13, 2015
@@ -23,17 +23,32 @@ module.exports = function(client) {
};

// setup model replication
var since = {push: -1, pull: -1};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: AFAIK, we use Node coding style where curly braces are surrounded by spaces: { push: -1, pull: -1 }.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a style guide for the style you describe? I've just been following the Google one at https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a style guide for the style you describe?

https://strongloop.atlassian.net/wiki/display/SL/Code+Style+Guide

We have had some discussions about spacing in array/object initialisation - see https://strongloop.atlassian.net/wiki/display/SL/Code+Style+Guide?focusedCommentId=21430339#comment-21430339

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY, I will take a look. ;)

@bajtos
Copy link
Member

bajtos commented May 13, 2015

Nice! I left one more comment, feel free to ignore it. The rest LGTM.

@bajtos bajtos assigned superkhau and unassigned bajtos May 13, 2015
- Enable "strict" and "persistUndefinedAsNull" flags for the Todo model
- Correctly store & send since checkpoints
- Remove deprecated events with operation hooks
- Implement error handler for change-tracking errors
- Rework conflict resolution in `client/ngapp/scripts/controllers/todo.js` to
  use the new API
@superkhau superkhau force-pushed the feature/refactor-with-sync-1.0-changes branch from d1345fa to a5dd541 Compare May 13, 2015 16:08
superkhau added a commit that referenced this pull request May 14, 2015
@superkhau superkhau merged commit 476bb23 into master May 14, 2015
@superkhau superkhau deleted the feature/refactor-with-sync-1.0-changes branch May 14, 2015 03:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants