itemsapi / itemsjs

Extremely fast faceted search engine in JavaScript - lightweight, flexible, and simple to use
Apache License 2.0
346 stars 41 forks source link

Problem with accessing itemsjs in VanillaJS #16

Closed cigolpl closed 6 years ago

cigolpl commented 6 years ago

After integration nwb and after loading itemsjs.js script I've encountered a obstacle with accessing itemsjs global variable for initializing search in vanillajs

This might be helpful for reproducing:

<html>
   <head>
      <!--the old version built with browserify. it's returning object correctly -->
      <!--<script src="https://unpkg.com/itemsjs@1.0.37/dist/itemsjs.min.js"></script>-->
      <!--the new version with nwp building. it's throwing an error: TypeError: itemsjs is not a function  -->
      <script src="https://cdn.rawgit.com/itemsapi/itemsjs/master/dist/itemsjs.min.js"></script>
   </head>
   <body>
      <script>
        // it should print an object like below:
        // {search: ƒ, aggregation: ƒ, reindex: ƒ}
        console.log(itemsjs());
      </script>
   </body>
</html>

@saminzadeh any idea how it could be solved ?

saminzadeh commented 6 years ago

I believe we should need to add the entry property to nwb build https://github.com/insin/nwb/blob/master/docs/Configuration.md#entry-string

I'll give it a shot

cigolpl commented 6 years ago

It was a good direction (entry) and also https://cdn.rawgit.com/itemsapi/itemsjs/master/dist/itemsjs.min.js seems to be always up-to-date with master but from some reason I cannot access itemsjs nor window.itemsjs. Seems or nwb is not exposing module itemsjs correctly or there is something wrong with my browser cache.

saminzadeh commented 6 years ago

Hmm, it seems that the unminified is fine now?

https://cdn.rawgit.com/itemsapi/itemsjs/master/dist/itemsjs.js

See this now: https://codesandbox.io/s/0ojmnxxokp

Anyway the minified file didnt get checked in?

cigolpl commented 6 years ago

On my computer it is undefined. Seems https://cdn.rawgit.com is unreliable and showing different results based on continent, browser, etc. I guess we should not trust it as an very up-to-date cdn.

I've reverted master branch to the old version and created development with nwb and new plugins. Not sure if that was a good decision.. Also although I've reverted master https://cdn.rawgit.com is not updated.. The plus of development we don't need to rush with changes

We should find a way for ensuring that wanna be master version is compatible with Vanilla Js, React Js, Node.js, etc in programmatic manner

saminzadeh commented 6 years ago

Sounds good, I can look into it further and will do on my on branch for now