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

Can I write a type file for an observ-struct using jsig2? #1

Open
ajoslin opened this issue Apr 26, 2016 · 1 comment
Open

Can I write a type file for an observ-struct using jsig2? #1

ajoslin opened this issue Apr 26, 2016 · 1 comment

Comments

@ajoslin
Copy link

ajoslin commented Apr 26, 2016

Typescript is too inflexible to let me write a type for both the wrapped and unwrapped version of an observ-struct without writing two separate type definitions.

@Raynos
Copy link
Owner

Raynos commented Apr 29, 2016

@ajoslin

observ-struct : <K, I, V <: Observ<I>>(Record<K, V>) => Observ<Record<K, I>> & Record<K, V>

I want to implement Records; which allow you to operate over a set of keys and values.

TypeScript has a feature request for this microsoft/TypeScript#1295

Honestly; if I wanted to a do a well typed version of observ or observ-struct I would start changing the interface.

aka instead of:

var state = ObservStruct({
    fruits: ObservStruct({
        apples: Observ(3),
        oranges: Observ(5)
    }),
    customers: Observ(5)
})
// plain object
var state = {
  fruits: {
    apples: 3,
    oranges: 5
  },
  customers: 5
}

// ObservCursor : <T>(T) => Cursor<T>
var cursor = ObservCursor(state);

// get : <T>(this: Cursor<T>) => T
cursor.get();

// update : <T>(this: Cursor<T>, path: String, value: any) => void
cursor.update('fruits.apples', 4);


var state = {
  fruits: null,
  customers: 5
}
var rootCursor = ObservCursor(state);

var fruitsState = {
  apples: 3,
  oranges: 5
}
var fruitCursor = ObservCursor(fruitsState);

// merge : <T, S>(this: Cursor<T>, keyPath: String, Cursor<S>) => void
cursor.merge('fruits', fruitCursor);

I have no idea of this ObservCursor would work. I would hope that merge() allows us to get some of the cool features we wanted from arbitrarly nested observ...

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