Giter Club home page Giter Club logo

Comments (19)

jedireza avatar jedireza commented on July 21, 2024

Looks like the node-util and the built-in util are not exactly the same.

Here is the util lib from core:
https://github.com/joyent/node/blob/master/lib/util.js#L632-L642

Even in 0.10:
https://github.com/joyent/node/blob/09b482886bdd3d863c3d4e7d71264eac0daaf9e1/lib/util.js#L554-L564

from dispatchr.

ezequiel avatar ezequiel commented on July 21, 2024

@jedireza

Good point. They aren't exactly the same. It seems node-util hasn't been updated in a year.

After browserifying, I see the entire util module included in my bundle. Is this necessary?

from dispatchr.

jedireza avatar jedireza commented on July 21, 2024

That doesn't sound desirable. IIRC Webpack has some optimizations we're taking advantage of to prevent this.

Here is our webpack config:
https://github.com/yahoo/fluxible.io/blob/master/Gruntfile.js#L123-L135

from dispatchr.

3den avatar 3den commented on July 21, 2024

The 'util' lib it is not really necessary we can do inheritance without it.

from dispatchr.

mridgway avatar mridgway commented on July 21, 2024

Agreed.

from dispatchr.

mridgway avatar mridgway commented on July 21, 2024

I think the best course of action might be to use the inherits module that @ezequiel mentions. It's 100% compatible with node.

from dispatchr.

3den avatar 3den commented on July 21, 2024

But Object.create is 100% compatible with node and the browser also it won't add any extra code to webpack

from dispatchr.

3den avatar 3den commented on July 21, 2024

take a look at the source code for https://github.com/joyent/node/blob/master/lib/util.js#L632-L642 it is just a wrapper for MyClass.prototype = Object.create(ParentClass.prototype);

from dispatchr.

mridgway avatar mridgway commented on July 21, 2024

inherits also sets MyClass._super and ensures that MyClass.prototype.constructor is set correctly. It's possible that downstream users are relying on these.

from dispatchr.

3den avatar 3den commented on July 21, 2024

I think the best solution would be to use ES6 classes this way we get real classes, but if we cannot do that yet it would be good to minimize dependencies.

The standard javascript way of Pseudo-classical inheritance is the one I sent on the PR and you can also see that example here => https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FObject%2Fcreate.

I never saw a case where the super_ was a good idea, would you ever use something like this.constructor.super_.someMethod.call(this, args)?

from dispatchr.

3den avatar 3den commented on July 21, 2024

The node/utils file is 20kb but I am not sure how webpack optimizes it. Usually it is a good idea to make JS libs as small and with as few dependencies as possible.

from dispatchr.

luiztiago avatar luiztiago commented on July 21, 2024

👍 I was having that same issue of webpack it would be cool to remove that dependency.

from dispatchr.

mridgway avatar mridgway commented on July 21, 2024

We are going to switch over to the inherits npm module for now until we start using ES6 classes.

from dispatchr.

3den avatar 3den commented on July 21, 2024

ES6 classes?! That sounds awesome! 👍

from dispatchr.

3den avatar 3den commented on July 21, 2024

are we going to use ES6 modules too? http://www.2ality.com/2014/09/es6-modules-final.html

from dispatchr.

mridgway avatar mridgway commented on July 21, 2024

Yeah. We need to get the builds figured out first, but we will use babel to generate ES5 exports.

from dispatchr.

mridgway avatar mridgway commented on July 21, 2024

This has been released in v0.3.0.

from dispatchr.

equalbackslash avatar equalbackslash commented on July 21, 2024

this doesn't appear to be released, possibly someone merged back use of 'util' module. It is unclear from commit history

from dispatchr.

mridgway avatar mridgway commented on July 21, 2024

You're totally right. Will look into this.

from dispatchr.

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.