GithubHelp home page GithubHelp logo

Comments (11)

daniel-lundin avatar daniel-lundin commented on June 18, 2024

I just added added some UMD boilerplate to add support for requirejs and browserify. I tested with require.js but I haven't used browserify before. Do you have the time to verify that it works with browserify as well?
Grab the latest snabbt.js or snabbt.min.js from master..

from snabbt.js.

daniel-lundin avatar daniel-lundin commented on June 18, 2024

Latest release has require.js and browserify support. published to bower and npm

npm install snabbt.js

Unfortunately some trash files was included in the publish, will fix for next release.

from snabbt.js.

sebastiandeutsch avatar sebastiandeutsch commented on June 18, 2024

Requiring it with browserify is quite quirky. You have to write:

var snabbt = require('snabbt.js').snabbt;

I would expect

var snabbt = require('snabbt.js')

Is that by design?

from snabbt.js.

daniel-lundin avatar daniel-lundin commented on June 18, 2024

Yes, it's quirky.
Well, sort of by design. The whole library is in "snabbtjs" namespace. When using without a module loader the snabbt-function is exposed as a global variable.
There is more than the snabbt-function that needs to be accessible, for example the matrix operations. That is why the require call cannot return the snabbt-function directly.

If you want it to work exactly like without the module loader you have to do this:

var snabbt = require('snabbt.js').snabbt;
var snabbtjs = require('snabbt.js');

Do you have any suggestions how it could be improved?

from snabbt.js.

sebastiandeutsch avatar sebastiandeutsch commented on June 18, 2024

Could you give me an example which externals you need to expose to the user?

from snabbt.js.

daniel-lundin avatar daniel-lundin commented on June 18, 2024

To use value feeding for example the Matrix API needs to be accessible.
I've thought about sending them as parameters in the value feed call instead. E.g.

snabbt(element, {
  value_feeder: function(i, ident, mult, trans, rotX, rotY, rotZ, scale, skew) {
    return mult(trans(100*i, 0, 0), rotX(2*Math.PI));
  }
}

I don't know how I feel about this, but at least it would allow for export of only the snabbt function..

from snabbt.js.

sebastiandeutsch avatar sebastiandeutsch commented on June 18, 2024

I understand. That many parameters are tricky and very verbose for the developer when he just needs scale. Another option would be to pass a $scope object that exposes the MatrixAPI as an object where mult, trans, ... are attributes.

Since value_feeder is a function another option would be to call it via call (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call) instead of calling value_feeder(tween_value) and provide a context with the scope variables. The user could use it like this:

snabbt(element, {
  value_feeder: function(i) {
    return this.mult(this.trans(100*i, 0, 0), this.rotX(2*Math.PI));
  }
}

But it might feel like to much magic.

from snabbt.js.

daniel-lundin avatar daniel-lundin commented on June 18, 2024

Great input.
I think I prefer the first approach, it's more explicit.
Even better would be to redesign the Matrix API so that the operations are instance methods returning this. Then the second parameter could be an identity matrix and all the operations could be chained on that:

snabbt(element, {
  value_feeder: function(i, matrix) {
    return matrix.trans(100*i, 0, 0).rotX(2*Math.PI);
  }
}

And while I'm at it I think I will get rid of the silly abbreviations. trans -> translate, rotX -> rotateX etc..
I'll sleep on it but I think this is the way to go.
Thoughts?

from snabbt.js.

sebastiandeutsch avatar sebastiandeutsch commented on June 18, 2024

Great idea. Go for it.

from snabbt.js.

daniel-lundin avatar daniel-lundin commented on June 18, 2024

Fixed in the latest release

from snabbt.js.

wolfgangschoeffel avatar wolfgangschoeffel commented on June 18, 2024

👍 Thanks!

from snabbt.js.

Related Issues (20)

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.