dojo / framework

Dojo Framework. A Progressive Framework for Modern Web Apps
https://dojo.io/
Other
586 stars 79 forks source link

withType should be for end users over custom create factories #894

Closed matt-gadd closed 3 years ago

matt-gadd commented 3 years ago

Enhancement

With https://github.com/dojo/framework/pull/819, there is simply no need to have these separate bespoke create factories such as createIcacheMiddleware anymore. The end user can use withType to stamp the types and that means we don't have to flip flop between separate exports for typed and untyped middleware.

before:

import { createIcacheMiddleware } from '@dojo/framework/core/middleware/icache'

const myIcache = createIcacheMiddleware<{ foo: string }();

after:

import icache from '@dojo/framework/core/middleware/icache'

const myIcache = icache.withType<{ foo: string }();
agubler commented 3 years ago

To note these two aren't quite like for like, for example the createIcacheMiddleware takes an interface for the state but the withType requires the API of the actual middleware, in this case it's something like ICacheResult<StateInterface>:

import icache, { ICacheResult } from '@dojo/framework/core/middleware/icache'

const myIcache = icache.withType<ICacheResult<{ foo: string }>>();