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

Example using the lbclient.js in polymer #3

Closed
nigeltiany opened this issue Sep 3, 2016 · 10 comments
Closed

Example using the lbclient.js in polymer #3

nigeltiany opened this issue Sep 3, 2016 · 10 comments

Comments

@nigeltiany
Copy link

nigeltiany commented Sep 3, 2016

How can the browserified files(The loopback Isomer) be used in a polymer component.

<script src="src/loopback/scripts/lbclient.js"></script>
<link rel="import" href="/src/app.html">
<body>
    <my-app></my-app>
</body>
<dom-module id="my-app">
    <template>
    <script>
        Polymer({
            is: 'my-app',
            authenticate: function () {
                //Call User method defined in the server ---> undefined
                User.create();
            }
        });
    </script>
</dom-module>

<link rel="import" href="src/loopback/scripts/lbclient.html">
<link rel="import" href="/src/app.html">
<body>
    <my-app></my-app>
</body>
<!--lbclient.html-->
<script src="lbclient.js"></script>
Polymer({
   is: 'my-app',
   authenticate: function () {
        //Call User method defined in the server ---> undefined
        User.create();
    }
});

@klarkc

@nigeltiany nigeltiany changed the title Example using the build.js bundle Example using the lbclient.js in polymer Sep 3, 2016
@klarkc
Copy link
Owner

klarkc commented Sep 8, 2016

Hello, sorry for the delay. You are right, this information is missing in README. There is a task in gulp, called lbclient, this task build the bundle.js file with content from client/loopback in client/scripts/bundle.js. This file is loaded at client/index.html:55. So to use the models you just require the lbclient anywhere, like:

<script> 
  var app = require('lbclient'); 
  var User = app.models.User;
  User.login({
    email: 'test@example.com',
    password: '12345'
  }, function(err, res) {
    if (err) {
      console.error('Login failed: ', err);
    } else {
      console.log('Logged in.');
    }
  });
</script>

You can have the docs regarding this here:
https://github.com/klarkc/polymer-loopback-starter-kit#loopback
https://docs.strongloop.com/display/public/LB/Running+LoopBack+in+the+browser

@nigeltiany
Copy link
Author

nigeltiany commented Sep 8, 2016

Yeah, i found that later in the docs. But somewhere in the 100,000+ lines of code there are errors. I think it was fs.readfilesync is not a function error and fs.readaddr is not a function error. Haven't found a way to solve this yet. not an issue related to this kit but have you encountered and solved this error?
I tried using b.transform('bfrs'); before piping out to the file. This didn't work. brfs @klarkc

@klarkc
Copy link
Owner

klarkc commented Sep 8, 2016

Strange, for me it is working, Did you tried to clean the bundle and create again? $ gulp clean

@klarkc
Copy link
Owner

klarkc commented Sep 8, 2016

Look at testing-lbclient for an working example here

@klarkc
Copy link
Owner

klarkc commented Sep 8, 2016

@nigeltiany Maybe it's related to the browserify version, or even node.js version. Are you trying with the latest versions of these packages?

@nigeltiany
Copy link
Author

nigeltiany commented Sep 8, 2016

I have updated all packages browserify 13.1.0 updated node -v 6.5.0 did a gulp clean then gulp serve but still the errors persists. @klarkc

@klarkc
Copy link
Owner

klarkc commented Sep 8, 2016

@nigeltiany , I tested here with exactly same versions, no problems 😕

@klarkc
Copy link
Owner

klarkc commented Sep 8, 2016

BTW the issue with the size of bundle is already know, the strongloop team is working on it, for now wrapping whole loopback into the bundle is the only workaround. strongloop/loopback#989

@klarkc
Copy link
Owner

klarkc commented Sep 8, 2016

I suggest you to open an issue in loopback repo about browserify loopback and your specific error. I guess this occurs only in Windows, but I am not sure.

@klarkc
Copy link
Owner

klarkc commented Sep 8, 2016

I'll close this for now, fell free to re-open if you have any updates on this.

@klarkc klarkc closed this as completed Sep 8, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants