jaxs 0.7.3 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/jaxs.d.ts CHANGED
@@ -1,7 +1,12 @@
1
+ import { PublishFromDom } from '.'
2
+ import { State as State_2 } from '.'
3
+ import { Store as Store_2 } from '.'
4
+ import { Subscribe as Subscribe_2 } from '.'
5
+
1
6
  export declare class App {
2
7
  window: Window
3
8
  document: Document
4
- publish: PublishFunction
9
+ publish: Publish<any>
5
10
  subscribe: Subscribe
6
11
  bus: JaxsBus
7
12
  state: State
@@ -29,7 +34,7 @@ export declare class App {
29
34
  }
30
35
 
31
36
  declare type AppAdditionListenerOptions = {
32
- state: State
37
+ state: State_2
33
38
  document: Document
34
39
  window: Window
35
40
  }
@@ -44,10 +49,6 @@ declare type AttributeInstructionData = {
44
49
  isSvg?: boolean
45
50
  }
46
51
 
47
- declare type AttributesWithChildren<T> = Props<T> & {
48
- children?: JsxCollection
49
- }
50
-
51
52
  export declare const bind: <ATTRIBUTES, STATE_MAP>({
52
53
  Template,
53
54
  viewModel,
@@ -96,10 +97,7 @@ declare const buildRouter: (
96
97
 
97
98
  declare type BusEventMatcher = string | RegExp
98
99
 
99
- export declare type BusListener<T> = (
100
- payload: T,
101
- listenerKit: ListenerKit,
102
- ) => void
100
+ export declare type BusListener<T> = (listenerKit: ListenerKit<T>) => void
103
101
 
104
102
  declare const catchAll: RouteMatcher
105
103
 
@@ -129,7 +127,7 @@ declare enum ChangeInstructionTypes {
129
127
  declare class Children implements Renderable {
130
128
  collection: Renderable[]
131
129
  parentElement?: JaxsElement
132
- constructor(jsxChildren: JsxCollection)
130
+ constructor(jsxChildren: RenderableCollection)
133
131
  render(renderKit: RenderKit, parentElement?: JaxsElement): JaxsNode[]
134
132
  generateDom(renderKit: RenderKit): JaxsNode[]
135
133
  attachToParent(dom: JaxsNodes): void
@@ -161,26 +159,25 @@ declare const createBus: () => {
161
159
 
162
160
  declare const createRouteState: (state: State) => void
163
161
 
164
- declare const createState: (publisher: StatePublisher) => State
162
+ declare const createState: (publisher: Publish<any>) => State
165
163
 
166
164
  declare type CustomPeriodicOptions = {
167
165
  timer: PeriodicTimerFunction
168
166
  }
169
167
 
170
- declare type CustomPeriodicPublisherOptions = RequiredPeriodicPublisherOptions &
171
- CustomPeriodicOptions
172
-
173
- declare type DefaultBusListenerOptions = {
174
- publish: PublishFunction
175
- eventName: string
176
- }
168
+ declare type CustomPeriodicPublisherOptions<T> =
169
+ RequiredPeriodicPublisherOptions<T> & CustomPeriodicOptions
177
170
 
178
171
  declare type DiffPair = {
179
172
  source: JaxsNode
180
173
  target: JaxsNode
181
174
  }
182
175
 
183
- declare type DomPublish = (eventName: string, domEvent: Event) => void
176
+ export declare const Equality: {
177
+ objects: (oldValue: Object_2, newValue: Object_2) => any
178
+ arrays: (oldValue: any[], newValue: any[]) => any
179
+ equal: (oldValue: any, newValue: any) => any
180
+ }
184
181
 
185
182
  declare type EventInstructionData = {
186
183
  name: string
@@ -246,8 +243,8 @@ declare type GeneralPeriodicOptions = {
246
243
  offset?: number
247
244
  }
248
245
 
249
- declare type GeneralPeriodicPublisherOptions =
250
- RequiredPeriodicPublisherOptions & GeneralPeriodicOptions
246
+ declare type GeneralPeriodicPublisherOptions<T> =
247
+ RequiredPeriodicPublisherOptions<T> & GeneralPeriodicOptions
251
248
 
252
249
  declare type InsertNodeData = {
253
250
  parent: JaxsElement
@@ -264,6 +261,14 @@ declare type InstructionData =
264
261
 
265
262
  declare type InstructionsUpdater = (instruction: ChangeInstruction) => void
266
263
 
264
+ export declare const Is: {
265
+ boolean: (value: any) => value is boolean
266
+ number: (value: any) => value is number
267
+ string: (value: any) => value is string
268
+ array: (value: any) => value is any[]
269
+ object: (value: any) => boolean
270
+ }
271
+
267
272
  declare class JaxsBus {
268
273
  options?: AppAdditionListenerOptions
269
274
  exactSubscriptions: ExactSubscriptions
@@ -273,7 +278,17 @@ declare class JaxsBus {
273
278
  subscribe<T>(matcher: BusEventMatcher, listener: BusListener<T>): Unsubscribe
274
279
  publish<T>(event: string, payload: T): void
275
280
  addListenerOptions(options: AppAdditionListenerOptions): void
276
- listenerOptions(event: string): ListenerKit
281
+ listenerOptions<T>(
282
+ event: string,
283
+ payload: T,
284
+ ): {
285
+ publish: any
286
+ payload: T
287
+ state: State
288
+ document: Document
289
+ window: Window
290
+ eventName: string
291
+ }
277
292
  }
278
293
 
279
294
  declare type JaxsElement = Element & JsxIded & JsxEventMapped
@@ -293,11 +308,11 @@ export declare namespace JaxsTypes {
293
308
  App,
294
309
  State,
295
310
  Store,
296
- StoreUpdaterBase,
297
311
  StoreUpdaterBoolean,
298
312
  StoreUpdaterList,
299
313
  StoreUpdaterObject,
300
314
  StoreUpdater,
315
+ CreateAppBuilderArguments,
301
316
  TextValue,
302
317
  JsxIded,
303
318
  JsxChangeId,
@@ -315,14 +330,16 @@ export declare namespace JaxsTypes {
315
330
  TagAttributes,
316
331
  TagEventAttributes,
317
332
  TagAttributesAndEvents,
318
- DomPublish,
319
- Subscribe,
320
333
  RenderKit,
321
334
  Renderable,
322
335
  StaticTemplate,
323
336
  TypedTemplate,
324
337
  Template,
325
- JsxCollection,
338
+ RenderableCollection,
339
+ StoreMap,
340
+ ViewModel,
341
+ BindSubscriptionList,
342
+ BindParams,
326
343
  ChangeInstructionTypes,
327
344
  RemoveInstructionData,
328
345
  AttributeInstructionData,
@@ -333,25 +350,18 @@ export declare namespace JaxsTypes {
333
350
  ChangeInstruction,
334
351
  ChangeInstructions,
335
352
  InstructionsUpdater,
336
- StoreMap,
337
- ViewModel,
338
- BindSubscriptionList,
339
- BindParams,
353
+ DiffPair,
354
+ CompileChildren,
355
+ PublishFromDom_2 as PublishFromDom,
356
+ Subscribe,
340
357
  AppAdditionListenerOptions,
341
- DefaultBusListenerOptions,
342
358
  ListenerKit,
343
- PublishFunction,
359
+ Publish,
344
360
  BusListener,
345
361
  BusEventMatcher,
346
362
  ExactSubscriptionData,
347
363
  FuzzySubscriptionData,
348
364
  Unsubscribe,
349
- CreateAppBuilderArguments,
350
- RouteState,
351
- AttributesWithChildren,
352
- DiffPair,
353
- CompileChildren,
354
- StatePublisher,
355
365
  StateTransactionUpdater,
356
366
  StoresCollection,
357
367
  StoreInitializationOptions,
@@ -359,8 +369,6 @@ export declare namespace JaxsTypes {
359
369
  UpdaterValue,
360
370
  StoreUpdaterOrValue,
361
371
  StoreListSorterFunction,
362
- RouteMatcher,
363
- RenderedRoute,
364
372
  PeriodicPublisher,
365
373
  RequiredPeriodicPublisherOptions,
366
374
  GeneralPeriodicOptions,
@@ -370,6 +378,9 @@ export declare namespace JaxsTypes {
370
378
  PublishPeriodicallyOptions,
371
379
  PeriodicTimerFunctionOptions,
372
380
  PeriodicTimerFunction,
381
+ RouteState,
382
+ RouteMatcher,
383
+ RenderedRoute,
373
384
  }
374
385
  }
375
386
 
@@ -377,9 +388,12 @@ export declare const jsx: {
377
388
  <T>(
378
389
  type: string | Template<T>,
379
390
  attributes: Props<T>,
380
- ...children: JsxCollection
391
+ ...children: RenderableCollection
381
392
  ): Renderable
382
- fragment<T>(attributes: Props<T>, maybeChildren: JsxCollection): Children
393
+ fragment<T>(
394
+ attributes: Props<T>,
395
+ maybeChildren: RenderableCollection,
396
+ ): Children
383
397
  }
384
398
 
385
399
  declare type JsxChangeId = {
@@ -387,8 +401,6 @@ declare type JsxChangeId = {
387
401
  index: number
388
402
  }
389
403
 
390
- declare type JsxCollection = (Renderable | TextValue)[]
391
-
392
404
  declare interface JsxEventMapped {
393
405
  eventMaps: EventMaps
394
406
  }
@@ -399,8 +411,14 @@ declare interface JsxIded {
399
411
 
400
412
  declare const linkNavigationEvent = 'go-to-href'
401
413
 
402
- declare type ListenerKit = AppAdditionListenerOptions &
403
- DefaultBusListenerOptions
414
+ declare type ListenerKit<T> = {
415
+ state: State_2
416
+ document: Document
417
+ window: Window
418
+ publish: Publish<any>
419
+ eventName: string
420
+ payload: T
421
+ }
404
422
 
405
423
  declare const locationChangeEvent = 'navigation:location-change'
406
424
 
@@ -414,7 +432,11 @@ export declare namespace messageBus {
414
432
  }
415
433
  }
416
434
 
417
- declare const navigate: (path: string, { publish, window }: ListenerKit) => void
435
+ declare const navigate: ({
436
+ payload: path,
437
+ publish,
438
+ window,
439
+ }: ListenerKit<string>) => void
418
440
 
419
441
  export declare namespace navigation {
420
442
  export {
@@ -435,14 +457,16 @@ declare type NullInstructionData = Record<string, never>
435
457
 
436
458
  declare type NullValues = null | undefined
437
459
 
438
- declare const onLinkClick: (domEvent: MouseEvent, options: ListenerKit) => void
460
+ declare type Object_2 = Record<string, any>
439
461
 
440
- declare const onLocationChange: (_: null, listenerOptions: ListenerKit) => void
462
+ declare const onLinkClick: (listenerKit: ListenerKit<MouseEvent>) => void
441
463
 
442
- declare interface PeriodicPublisher {
464
+ declare const onLocationChange: (listenerKit: ListenerKit<null>) => void
465
+
466
+ declare interface PeriodicPublisher<T> {
443
467
  event: string
444
- publish: PublishFunction
445
- payload?: any
468
+ publish: Publish<T>
469
+ payload?: T
446
470
  start: () => void
447
471
  stop: () => void
448
472
  }
@@ -458,8 +482,8 @@ declare type PeriodicTimerFunctionOptions = {
458
482
  }
459
483
 
460
484
  export declare type Props<T> = Partial<{
461
- __source: ReactSourceObject
462
- children: JsxCollection
485
+ __source?: ReactSourceObject
486
+ children: RenderableCollection
463
487
  }> &
464
488
  T
465
489
 
@@ -468,19 +492,21 @@ declare type PropValue =
468
492
  | NullValues
469
493
  | boolean
470
494
  | ReactSourceObject
471
- | JsxCollection
495
+ | RenderableCollection
472
496
 
473
- export declare type PublishFunction = (event: string, payload: any) => void
497
+ export declare type Publish<T> = (event: string, payload: T) => void
498
+
499
+ declare type PublishFromDom_2 = Publish<Event>
474
500
 
475
501
  declare const publishLocation: (app: App) => void
476
502
 
477
- declare const publishPeriodically: (
478
- options: PublishPeriodicallyOptions,
503
+ declare const publishPeriodically: <T>(
504
+ options: PublishPeriodicallyOptions<T>,
479
505
  ) => () => void
480
506
 
481
- declare type PublishPeriodicallyOptions =
482
- | GeneralPeriodicPublisherOptions
483
- | CustomPeriodicPublisherOptions
507
+ declare type PublishPeriodicallyOptions<T> =
508
+ | GeneralPeriodicPublisherOptions<T>
509
+ | CustomPeriodicPublisherOptions<T>
484
510
 
485
511
  declare type ReactSourceObject = {
486
512
  fileName: string
@@ -497,6 +523,8 @@ export declare interface Renderable {
497
523
  render: (renderKit: RenderKit, parentElement?: JaxsElement) => JaxsNode[]
498
524
  }
499
525
 
526
+ declare type RenderableCollection = Renderable[]
527
+
500
528
  export declare type RenderedRoute = {
501
529
  Partial: StaticTemplate
502
530
  match: RouteMatcher
@@ -505,16 +533,16 @@ export declare type RenderedRoute = {
505
533
  declare type RenderKit = {
506
534
  document: Document
507
535
  window: Window
508
- publish: DomPublish
509
- subscribe: Subscribe
510
- state: State
536
+ publish: PublishFromDom
537
+ subscribe: Subscribe_2
538
+ state: State_2
511
539
  parent?: JaxsNode | null
512
540
  }
513
541
 
514
- declare type RequiredPeriodicPublisherOptions = {
542
+ declare type RequiredPeriodicPublisherOptions<T> = {
515
543
  event: string
516
- publish: PublishFunction
517
- payload?: any
544
+ publish: Publish<T>
545
+ payload?: T
518
546
  }
519
547
 
520
548
  declare class Root {
@@ -568,12 +596,12 @@ declare namespace start {
568
596
  declare const startNavigation: (app: App) => void
569
597
 
570
598
  export declare class State {
571
- publisher: StatePublisher
599
+ publisher: Publish<any>
572
600
  stores: StoresCollection
573
601
  eventNamePrefix: string
574
602
  notifications: Set<string>
575
603
  inTransaction: boolean
576
- constructor(publisher: StatePublisher)
604
+ constructor(publisher: Publish<any>)
577
605
  create<T>(name: string, initialState: T): Store<T>
578
606
  store<T>(name: string): Store<T>
579
607
  get<T>(name: string): T
@@ -590,8 +618,6 @@ export declare namespace state {
590
618
  export { eventName, State, createState, Store, updaters }
591
619
  }
592
620
 
593
- declare type StatePublisher = (event: string, payload: any) => void
594
-
595
621
  declare type StateTransactionUpdater = (collection: StoresCollection) => void
596
622
 
597
623
  export declare type StaticTemplate = () => Renderable
@@ -600,7 +626,7 @@ export declare class Store<T> {
600
626
  parent: State
601
627
  name: string
602
628
  updater: StoreUpdater<T>
603
- _value: T
629
+ private _value
604
630
  initialValue: T
605
631
  constructor(options: StoreInitializationOptions<T>)
606
632
  get ['value'](): T
@@ -615,7 +641,7 @@ declare type StoreDataUpdater<T> = (originalValue: T) => T
615
641
 
616
642
  declare type StoreInitializationOptions<T> = {
617
643
  name: string
618
- parent: State
644
+ parent: State_2
619
645
  value: T
620
646
  }
621
647
 
@@ -625,48 +651,52 @@ declare type StoreMap = {
625
651
  [key: string]: any
626
652
  }
627
653
 
628
- declare type StoresCollection = Record<string, Store<any>>
654
+ declare type StoresCollection = Record<string, Store_2<any>>
629
655
 
630
- export declare type StoreUpdater<T> =
631
- | StoreUpdaterBase<T>
656
+ declare type StoreUpdater<T> =
632
657
  | StoreUpdaterObject<T extends object ? T : never>
633
658
  | StoreUpdaterBoolean
634
659
  | StoreUpdaterList<T>
635
660
 
636
- export declare class StoreUpdaterBase<T> {
637
- store: Store<T>
638
- constructor(store: Store<T>)
639
- update(updater: StoreUpdaterOrValue<T>): void
661
+ declare class StoreUpdaterBoolean {
662
+ store: Store<boolean>
663
+ constructor(store: Store<boolean>)
664
+ private update
665
+ private get value()
640
666
  reset(): void
641
- get value(): T
642
- }
643
-
644
- export declare class StoreUpdaterBoolean extends StoreUpdaterBase<boolean> {
645
667
  toggle(): void
646
668
  setTrue(): void
647
669
  setFalse(): void
648
670
  }
649
671
 
650
- export declare class StoreUpdaterList<T> extends StoreUpdaterBase<T[]> {
672
+ declare class StoreUpdaterList<T> {
673
+ store: Store<T[]>
674
+ constructor(store: Store<T[]>)
675
+ private update
676
+ private get value()
677
+ reset(): void
651
678
  push(element: T): void
652
679
  pop(): T
653
680
  unshift(element: T): void
654
681
  shift(): T
655
- addSorter(name: string, sorter: StoreListSorterFunction<T>): void
656
682
  sortBy(sorter: StoreListSorterFunction<T>): void
657
683
  insertAt(index: number, item: T): void
658
684
  remove(value: T): void
659
685
  removeBy(matcherFunction: (value: T) => boolean): void
660
686
  }
661
687
 
662
- export declare class StoreUpdaterObject<
663
- T extends object,
664
- > extends StoreUpdaterBase<T> {
688
+ declare class StoreUpdaterObject<T extends object> {
689
+ store: Store<T>
690
+ constructor(store: Store<T>)
691
+ private update
692
+ private get value()
693
+ reset(): void
665
694
  updateAttribute(name: keyof T, value: T[keyof T]): void
666
695
  updateDynamicAttribute(name: string, value: any): void
667
696
  isKey(key: string): boolean
668
697
  isValueType(key: keyof T, value: any): boolean
669
698
  resetAttribute(name: keyof T): void
699
+ updateAttributes(values: Partial<T>): void
670
700
  }
671
701
 
672
702
  declare type StoreUpdaterOrValue<T> = UpdaterValue<T> | StoreDataUpdater<T>
@@ -680,7 +710,10 @@ declare const subscribeToHistoryChange: (app: App) => void
680
710
 
681
711
  declare const subscribeToNavigation: (app: App) => void
682
712
 
683
- declare type TagAttributes = SourceMap & Record<string, string>
713
+ declare type TagAttributes = SourceMap &
714
+ Record<string, string> & {
715
+ __source?: ReactSourceObject
716
+ }
684
717
 
685
718
  declare type TagAttributesAndEvents = {
686
719
  attributes: TagAttributes
@@ -697,6 +730,47 @@ export declare type TypedTemplate<T> = (props: Props<T>) => Renderable
697
730
 
698
731
  declare type Unsubscribe = () => void
699
732
 
733
+ export declare const Update: {
734
+ RecordStore: {
735
+ reset: <T>(store: Store<T>) => void
736
+ resetAttribute: <T>(store: Store<T>, name: keyof T) => void
737
+ updateAttribute: <T>(
738
+ store: Store<T>,
739
+ name: keyof T,
740
+ value: T[keyof T],
741
+ ) => void
742
+ updateAttributes: <T>(store: Store<T>, values: Partial<T>) => void
743
+ }
744
+ BooleanStore: {
745
+ toggle: (store: Store<boolean>) => void
746
+ setTrue: (store: Store<boolean>) => void
747
+ setFalse: (store: Store<boolean>) => void
748
+ reset: (store: Store<boolean>) => void
749
+ }
750
+ ListStore: {
751
+ push: <T>(store: Store<T[]>, element: T) => void
752
+ pop: <T>(store: Store<T[]>) => T
753
+ unshift: <T>(store: Store<T[]>, element: T) => void
754
+ shift: <T>(store: Store<T[]>) => T
755
+ sortBy: <T>(store: Store<T[]>, sorter: StoreListSorterFunction<T>) => void
756
+ insertAt: <T>(store: Store<T[]>, index: number, item: T) => void
757
+ remove: <T>(store: Store<T[]>, value: T) => void
758
+ removeBy: <T>(
759
+ store: Store<T[]>,
760
+ matcherFunction: (value: T) => boolean,
761
+ ) => void
762
+ reset: <T>(store: Store<T[]>) => void
763
+ }
764
+ ArrayModifiers: {
765
+ remove: <T>(originalCollection: T[], itemToRemove: T) => T[]
766
+ removeBy: <T>(
767
+ originalCollection: T[],
768
+ matcherFunction: (value: T) => boolean,
769
+ ) => T[]
770
+ insertAt: <T>(originalCollection: T[], index: number, item: T) => T[]
771
+ }
772
+ }
773
+
700
774
  declare type UpdateEventInstructionData = {
701
775
  name: string
702
776
  sourceValue: EventListener