Snap icon indicating copy to clipboard operation
Snap copied to clipboard

Some extension issues

Open ToonTalk opened this issue 3 years ago • 6 comments

So I defined 2 new primitives: https://ecraft2learn.github.io/ai/js/ecraft2learn_snap_extension.js

And I generated 6 libraries: https://github.com/ecraft2learn/ai/tree/master/AI-Teacher-Guide/7

And 6 associated projects that illustrate their use: https://github.com/ecraft2learn/ai/tree/master/projects/7 (run and call.xml updates any eCraft2Learn project when imported)

I had troubles with the SnapExtensions.primitives.set command 'this' was bound to the DOM window not some Snap! object. (But I programmed around that so my libraries work anyway.)

It worked fine when I added 'https://ecraft2learn.github.io/ai/' to the urls of SnapExtensions on my local file system. (Strangely, when I first tried this I repeatedly got strange error messages but it is working fine today without any obvious change.)

As advised I tested all this in the released dev version where I turned on JS clicked a block, turned it off, and tested the rest.

These libraries could be added to Snap! libraries. Ideally all 6 should be grouped together if you all think they should be included.

ToonTalk avatar Aug 02 '21 17:08 ToonTalk

Hi Ken,

this looks great! I'm excited that you're exploring the new extensions system.

If you use the ES6 arrow notation for functions this is scoped differently than when you use the function keyword. For the sake of dynamically binding extensions primitives to sprites or the stage I'd strongly recommend to not use the arrow notation, but function. In fact, good catch, I'll update the documentation accordingly.

I'll be taking a vacation starting next week for most of August. Let's talk about the best way to integrate your extensions afterwards. I think it would be great to simply include all of them, if you like!

jmoenig avatar Aug 02 '21 22:08 jmoenig

Thanks. Just learned about the arrow function differences.

One concern I have about becoming a Snap! library is how often I update them. I just checked GitHub and one library had 8 updates in 2020 and about half were in September.

Perhaps libraries should optionally load from a URL and only if running locally or if there is an error is the local file used.

Have a good holiday.

ToonTalk avatar Aug 03 '21 08:08 ToonTalk

We can whitelist a domain of yours, too. So you could load JS from outside of the repo.

-- Michael Ball From my iPhone michaelball.co

On Aug 3, 2021, at 1:43 AM, Ken Kahn @.***> wrote:

 Thanks. Just learned about the arrow function differences.

One concern I have about becoming a Snap! library is how often I update them. I just checked GitHub and one library had 8 updates in 2020 and about half were in September.

Perhaps libraries should optionally load from a URL and only if running locally or if there is an error is the local file used.

Have a good holiday.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

cycomachead avatar Aug 03 '21 11:08 cycomachead

you could then also use the url block to first check your own domain, and if it times out / there is no result, you could call the primitive load command to load your extensions

jmoenig avatar Aug 03 '21 11:08 jmoenig

Can a library run a block? I assumed it only imports blocks while I think I'm hearing that the library would run a url block or do a src_load by running a prim block.

As I investigated more whether it would make sense to support off-line use of all the eCraft2Learn resources I discovered that all the models and data come to about 1GB. So I think offline users should just get those files (somehow) and then run Snap! offline. So in my case I believe that if a user can't get files from ecraft2learn.github.io then my libraries are pretty useless.

So what I would like is to have my libraries in the Snap! dialog but that they are loaded from URLs to ecraft2learn.github.io (suitably whitelisted). I withdraw the suggestion that it falls back on local files.

ToonTalk avatar Aug 03 '21 13:08 ToonTalk

a library can have a block that loads a JS extension from a url. Before you run that primitive you could check your own server, and only fall back on the load primitive if your server is unreachable.

jmoenig avatar Aug 03 '21 22:08 jmoenig