Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make immstruct instantiable? #10

Closed
dashed opened this issue Dec 17, 2014 · 12 comments
Closed

Make immstruct instantiable? #10

dashed opened this issue Dec 17, 2014 · 12 comments

Comments

@dashed
Copy link
Contributor

dashed commented Dec 17, 2014

I'm mulling over an idea to make immstruct instantiable. Pretty much in the same manner that EventEmitter is instantiable.

I'm suggesting this so that something like new immstruct().instances would be compartmentalized. I have a library that's a work-in-progress that decorates the immstruct, and one feature I have is that it creates an associated meta-structure for a given immstruct structure.

@mikaelbr
Copy link
Member

Do you mean something like the following?

var Structure = require('immstruct/src/structure');

var structure = new Structure({
   data: myImmutableOrNotData
});

@dashed
Copy link
Contributor Author

dashed commented Dec 17, 2014

I was thinking of just immstruct, so I don't have to keep track of instances externally 😄.

@dashed dashed mentioned this issue Dec 17, 2014
@mikaelbr
Copy link
Member

I don't quite understand. Do you want to be able to create an instance of the "instance manager"?

@dashed
Copy link
Contributor Author

dashed commented Dec 17, 2014

Yep.

This is my use case:

var immstruct = require('immstruct');

var chest = new immstruct();
var meta = new immstruct();

var structure = chest({ a: { b: { c: 1 } } });
var metaStructure = meta(structure.key);

@dashed
Copy link
Contributor Author

dashed commented Dec 17, 2014

This is a drastic change in API. So I'm throwing ideas around.

@mikaelbr
Copy link
Member

Is it essential that they share key?

Or could you just do

var immstruct = require('immstruct');
var structure = immstruct({ a: { b: { c: 1 } } });
var metaStructure = immstruct(structure.key + 'meta');

It doesn't need to be the biggest API-change, though.

Could rewrite the internals to be a instancable, and expose something like:

module.exports = new Immstruct();
module.exports.Immstruct = Immstruct;

// Some other file:
var Immstruct = require('immstruct').Immstruct;

new Immstruct();

@dashed
Copy link
Contributor Author

dashed commented Dec 17, 2014

It's not absolutely essentially that they share keys; but I use it to match each other in a map. I've thought about + 'meta' concatenation, but I thought it wasn't elegant.

At the moment, I'm keeping track of Structure instances externally. But eventually I'd like to delegate this to just immstruct.

@mikaelbr
Copy link
Member

At the moment, I'm keeping track of Structure instances externally. But eventually I'd like to delegate this to just immstruct.

This is what I don't really get. immstruct-factory is a way to keep track of Structure, why would you do this externally? To share keys? Maybe I'm a bit slow today 😴

@dashed
Copy link
Contributor Author

dashed commented Dec 17, 2014

I just didn't want to pollute the immstruct.instances object. 😄

To clarify, the external Structure instances I'm talking about are the ones being instantiated externally; not via immstruct.

@mikaelbr mikaelbr added this to the 1.3.0 milestone Dec 23, 2014
@mikaelbr mikaelbr modified the milestone: 1.3.0 Jan 7, 2015
@mikaelbr
Copy link
Member

mikaelbr commented Feb 8, 2015

Fixed in 84a35e1

@mikaelbr mikaelbr closed this as completed Feb 8, 2015
@mikaelbr
Copy link
Member

mikaelbr commented Feb 8, 2015

Usage is

var local = new immstruct.Immstruct();

Default usage (without own instance) remains the same as before.

@dashed
Copy link
Contributor Author

dashed commented Feb 8, 2015

Awesome thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants